Forked from greathmaster/pmpro-custom-email-templates-for-expiring-emails.php
Last active
December 1, 2021 16:49
-
-
Save kimwhite/1042c9c806fd66c2febdfb9f66a43e7f 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
<?php | |
/** | |
* This recipe will Add Custom Templates to your "Email Templates" area, so you can edit them. | |
* 2nd fuction will send them off depending on Level. | |
* You will have to create these email templates using this method: | |
* https://www.paidmembershipspro.com/documentation/member-communications/customizing-email-templates/ | |
* 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/ | |
*/ | |
// start cut and paste below here | |
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', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment