Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Last active January 24, 2024 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryOJob/db19e2a60f9c4bdbaedefca1b4af909f to your computer and use it in GitHub Desktop.
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
<?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 );
@MaryOJob
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment