Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/273e955295698364131490a36be77279 to your computer and use it in GitHub Desktop.
Save kimwhite/273e955295698364131490a36be77279 to your computer and use it in GitHub Desktop.
<?php
/**
* Customize the 'checkout_free' email template based on membership level.
*
* This function modifies the email subject and body for Level 1, (you can chage the ID)
* while leaving other levels with the default template.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_email_filter_checkout_free_per_level( $email ) {
// Check if the email being sent is the 'checkout_free' template.
if ( $email->template == 'checkout_free' ) {
// Retrieve the membership level ID from the email data.
$level_id = $email->data['membership_id'];
// Customize the email for Level 1.
if ( $level_id == 1 ) {
$email->subject = 'Welcome to Level 1!';
$email->body = 'Thank you for joining Level 1. Here are your exclusive benefits...';
}
// For other free levels, you can add additional conditions if needed.
// Otherwise, they will use the default 'checkout_free' template.
}
// Replace any remaining email variables with the actual data.
if ( is_array( $email->data ) ) {
foreach ( $email->data as $key => $value ) {
if ( 'body' != $key ) {
$email->body = str_replace( '!!' . $key . '!!', $value, $email->body );
$email->subject = str_replace( '!!' . $key . '!!', $value, $email->subject );
}
}
}
return $email;
}
add_filter( 'pmpro_email_filter', 'my_pmpro_email_filter_checkout_free_per_level', 99, 1 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment