Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active November 10, 2020 15:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/86e38ab9d0368dda34ae1b62e8da9f21 to your computer and use it in GitHub Desktop.
Save andrewlimaza/86e38ab9d0368dda34ae1b62e8da9f21 to your computer and use it in GitHub Desktop.
Change confirmation email contents in Paid Memberships Pro according to user level checkout.
<?php
/**
* Adjust email template according to user's level that they are checking out for.
* Add this code to your PMPro Customizations plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* For more information in customizing emails in Paid Memberships Pro visit - https://www.paidmembershipspro.com/documentation/member-communications/customizing-email-templates/
* List of available email templates - https://www.paidmembershipspro.com/documentation/member-communications/list-of-pmpro-email-templates/
*/
function adjust_pmpro_email_according_to_level( $email ){
//store email templates in an array.
$pmpro_email_templates = array( 'checkout_free', 'checkout_check', 'checkout_express', 'checkout_freetrial', 'checkout_paid', 'checkout_trial' ); //Email templates that possibly are sent out to user's when they checkout with PMPro.
//Get the level that the user is checking out for.
$level_for_email_change = $email->data['membership_id'];
if( in_array( $email->template, $pmpro_email_templates ) ){
switch ( $level_for_email_change ) {
case '1':
$email->subject = 'This subject will change for user level 1';
$email->body = 'This will change the user\'s body text for confirmation email for level 1';
break;
case '3':
$email->subject = 'This subject will change for user level 3';
$email->body = 'This will change the user\'s body text for confirmation email for level 3';
break;
case '5':
$email->subject = 'This subject will change for user level 5';
$email->body = 'This will change the user\'s body text for confirmation email for level 5';
break;
default:
//leave empty to not do any changes to email.
break;
}
}
return $email;
}
add_filter( 'pmpro_email_filter', 'adjust_pmpro_email_according_to_level' );
@andrewlimaza
Copy link
Author

Be sure to adjust line 12 to only adjust certain email templates and not all!

@andrewlimaza
Copy link
Author

Line 17 could change to something like

if ( 'checkout_free' == $email->template ) {

This would only affect the 'checkout_free' email template.

@mallinamala
Copy link

mallinamala commented Oct 10, 2020

$pmpro_invoice->getUser();
$pmpro_invoice->getMembershipLevel();
$confirmation_message .= "

" . sprintf(__('Below are details about your membership account and a receipt for your initial membership invoice. A welcome message with a copy of your initial membership invoice has been sent to your email %s.', 'paid-memberships-pro' ), $pmpro_invoice->user->user_login) . "

";

I changed the membership confirmation message in confirmation.php, but it is not refecting at ../membership-account/membership-confirmation/?level=1

in Checkout.php there are 2 membership confirmation messages I changed, but not refecting. What is the solution for this

@andrewlimaza
Copy link
Author

@mallinamala this is for the confirmation email and not the confirmation page, you'd need to use the following filter to adjust the confirmation page text - https://github.com/strangerstudios/paid-memberships-pro/blob/dev/pages/confirmation.php#L42

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