Created
April 16, 2021 13:18
-
-
Save ipokkel/b6578a17005cd26388a1a8fbedb0bcc2 to your computer and use it in GitHub Desktop.
Create the !!custom_message!! shortcode for the Email Templates Admin Editor Add On and set a custom message per membership level.
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 | |
/** | |
* This recipe adds a custom email shortcode !!custom_message!! that can be | |
* used in the Email Templates Admin Editor. | |
* | |
* 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_custom_data_per_level( $data, $email ) { | |
// Set a default custom message | |
$custom_message = ''; // Optional: add default custom message for all levels, e.g. 'This is my custom message' | |
// Is this a checkout email for the member? | |
if ( strpos( $email->template, 'checkout' ) !== false && strpos( $email->template, 'admin' ) === false ) { | |
// which level is this email for? | |
$level_for_email = $email->data['membership_id']; | |
// Set custom message per level | |
switch ( $level_for_email ) { | |
case '1': | |
$custom_message = '<p>My custom message for level 1</p>'; | |
break; | |
case '2': | |
$custom_message = '<p>My custom message for level 2</p>'; | |
break; | |
} | |
} | |
// Let's only add the message if it is not already added. | |
if ( empty( $data['custom_message'] ) ) { | |
// add !!custom_message!! shortcode | |
$data['custom_message'] = $custom_message; | |
} | |
return $data; | |
} | |
add_filter( 'pmpro_email_data', 'my_pmpro_email_custom_data_per_level', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment