Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active February 2, 2023 13:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andrewlimaza/598bf41b2ee2a29f2a76d017d4323137 to your computer and use it in GitHub Desktop.
Save andrewlimaza/598bf41b2ee2a29f2a76d017d4323137 to your computer and use it in GitHub Desktop.
Send a custom email when a user checks out for a pmpro level.
<?php
/**
* Add this code to your PMPro Customizations Plugin - http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* This function below sends a custom HTML email to the user that checks out for a pmpro membership level, easily extendible to send to admins, or specific users and so on.
* Website: https://paidmembershipspro.com
*/
//let's send a custom email after user checkouts. This will not send an email if an admin changes user's level inside member area.
function custom_email_after_checkout( $user_id, $morder ){
$user_details = get_userdata( $user_id ); //get user data for user checking out.
$my_email = new PMProEmail();
$my_email->email = $user_details->user_email; //who to send the email to - send to user that is checking out.
$my_email->subject = 'This is a custom subject header'; //change this to the header you would like to use.
$my_email->template = 'My Custom Email'; //custom name of email template.
$my_email->body = '<p>Hi there,</p>'; //header of body content goes here
$my_email->body .= '<p>Thank you for your purchase. {Change this text} </p>'; //body content goes here.
$my_email->body .= '<p>Best Regards,</p> My Site Name.'; //footer content goes here.
$my_email->sendEmail();
}
add_action( 'pmpro_after_checkout', 'custom_email_after_checkout', 10, 2 );
@kimwhite
Copy link

This gives me a "Fatal error: Uncaught ArgumentCountError:" , until I remove $morder.

Also, can email variables like !!billing_address!! be used in the body. If yes, how can they be added?

@andrewlimaza
Copy link
Author

Updated the gist @kimwhite, passed in the '2' on last line to force the amount of parameters passed through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment