Skip to content

Instantly share code, notes, and snippets.

@scottsousa
Last active May 22, 2018 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottsousa/6700307 to your computer and use it in GitHub Desktop.
Save scottsousa/6700307 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Add custom confirmation message for a level to checkout e-mail templates without creating a custom template. See comments in code for more details.
/**
* This function allows a custom confirmation message to be added to a checkout e-mail template. This will allow you to add
* your custom confirmation message to an e-mail template, without creating your own custom template in your theme.
*
* We're checking for the "checkout_" prefix on the e-mail template name and if we have current user data.
* We're then getting the custom confirmation level based on the current user data.
* We replace the 'is now active.</p>' portion of the body to append the confirmation message.
*/
add_filter( 'pmpro_email_body', 'my_pmpro_email_body', 10, 2 );
function my_pmpro_email_body( $body, $email ) {
global $wpdb, $current_user;
// If this is a "checkout" e-mail and we have a current user
if ( strpos( $email->template, 'checkout_' ) === 0 && ! empty( $current_user ) ) {
// Confirmation message for this level
$level_message = $wpdb->get_var( "SELECT l.confirmation FROM $wpdb->pmpro_membership_levels l LEFT JOIN $wpdb->pmpro_memberships_users mu ON l.id = mu.membership_id WHERE mu.status = 'active' AND mu.user_id = '" . $current_user->ID . "' LIMIT 1" );
if( ! empty( $level_message ) ) {
// Replace the 'is now active.</p>' string to append the confirmation message
$body = str_replace( 'is now active.</p>', 'is now active.</p> ' . $level_message, $body );
}
}
return $body;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment