Created
July 27, 2018 06:25
-
-
Save greathmaster/db9252820020c8a017404df4333c4ba7 to your computer and use it in GitHub Desktop.
pmpro email templates example for custom template for each 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
function my_pmproet_templates( $pmproet_email_defaults ) { | |
$pmproet_email_defaults['membership_expiring_1'] = array( | |
'subject' => __( 'Custom subject for !!membership_level_name!!', 'pmpro-customizations'), | |
'description' => __( 'Membership Expiring Level 1', 'pmpro-customizations'), | |
'body' => __('Custom body for level 1', 'pmpro-customizations'), | |
); | |
$pmproet_email_defaults['membership_expiring_2'] = array( | |
'subject' => __( 'Custom subject for !!membership_level_name!!', 'pmpro-customizations'), | |
'description' => __( 'Membership Expiring Level 2', 'pmpro-customizations'), | |
'body' => __('Custom body for level 2', 'pmpro-customizations'), | |
); | |
return $pmproet_email_defaults; | |
} | |
add_filter('pmproet_templates', 'my_pmproet_templates', 10, 1); | |
function my_pmpro_email_filter($email) | |
{ | |
$user = get_user_by('login', $email->data['user_login']); | |
$user_id = $user->ID; | |
if($email->template == 'membership_expiring') | |
{ | |
if(pmpro_hasMembershipLevel(1, $user_id)) | |
$email->template = 'membership_expiring_1'; | |
if(pmpro_hasMembershipLevel(2, $user_id)) | |
$email->template = 'membership_expiring_2'; | |
} | |
return $email; | |
} | |
add_action('pmpro_email_filter', 'my_pmpro_email_filter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment