Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/b6578a17005cd26388a1a8fbedb0bcc2 to your computer and use it in GitHub Desktop.
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.
<?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