Last active
February 7, 2025 20:32
-
-
Save ipokkel/f90b1199d8449002a9c439b7e01c264d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Example usage of the pmpro_email_filter hook to customize the checkout_free email per level. | |
* | |
* 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 ) { | |
if ( $email->template == 'checkout_free' ) { | |
$level_id = $email->data['membership_id']; | |
if ( $level_id == 1 ) { | |
$email->subject = 'Subject line for level 1'; | |
$email->body = 'This is the content/body of the email for members who checked out for level 1'; | |
} | |
if ( $level_id == 2 ) { | |
$email->subject = 'Subject line for level 2'; | |
$email->body = 'This is the content/body of the email for members who checked out for level 2'; | |
} | |
} | |
// Let's check for any remaining email variables and replace them with the 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