Last active
January 24, 2024 07:54
-
-
Save MaryOJob/db19e2a60f9c4bdbaedefca1b4af909f to your computer and use it in GitHub Desktop.
Change the email address for admin-related emails in Paid Memberships Pro for different levels
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 // do not copy this line | |
/** | |
* Change the email address for admin-related emails in Paid Memberships Pro for different levels. | |
* Follow this guide to add custom code to your WordPress site - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_change_admin_to_email( $user_email, $email ) { | |
// Check the email template for different levels | |
if ( strpos( $email->template, "_admin" ) !== false ) { | |
// Change email address based on membership level | |
$membership_level = pmpro_getMembershipLevelForUser( get_current_user_id() ); | |
if ( $membership_level ) { | |
$level_id = $membership_level->id; | |
// Change email addresses for different membership levels | |
switch ( $level_id ) { | |
case 1: | |
$user_email = 'me+1@maryjob.xyz'; | |
break; | |
case 2: | |
$user_email = 'me+2@maryjob.xyz'; | |
break; | |
case 3: | |
$user_email = 'me+3@maryjob.xyz'; | |
break; | |
case 4: | |
$user_email = 'me+4@maryjob.xyz'; | |
break; | |
// Add more cases as needed for other levels | |
// ... | |
default: | |
// Use a default email address for any other level | |
$user_email = 'me@maryjob.xyz'; | |
break; | |
} | |
} | |
} | |
return $user_email; | |
} | |
add_filter( "pmpro_email_recipient", "my_pmpro_change_admin_to_email", 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://gist.github.com/andrewlimaza/78a4e1fb266b633aa5b138047576bfcc