Last active
April 4, 2021 03:25
-
-
Save ideadude/135b29b47ebf04c3d094773625ff4707 to your computer and use it in GitHub Desktop.
Always send the checkout_free confirmation email in PMPro when changing a user's level in the admin dashboard.
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
/** | |
* Always send the checkout_free confirmation email | |
* when changing a user's level in the admin dashboard. | |
*/ | |
function my_send_pmpro_confirmation_emails_from_dashboard( $level_id, $user_id, $cancel_level_id ) { | |
// If we're not in the dashboard, this is probably a checkout on the frontend | |
if ( ! is_admin() ) { | |
return; | |
} | |
// If you want to exclude certain level ids, add them here. | |
$excluded_level_ids = array(); | |
// Send email if level > 0 and is not excluded. | |
if( !empty( $level_id ) && ! in_array( $level_id, $excluded_level_ids ) ) { | |
$email_user = get_userdata( $user_id ); | |
$membership_levels = pmpro_getMembershipLevelsForUser( $user_id ); | |
// In case of MMPU, let's find the specific level we're wondering about | |
foreach( $membership_levels as $membership_level ) { | |
if ( $membership_level->id == $level_id ) { | |
$email_user->membership_level = $membership_level; | |
break; | |
} | |
} | |
$pmproemail = new PMProEmail(); | |
$pmproemail->sendCheckoutEmail( $email_user ); | |
} | |
} | |
add_action( 'pmpro_after_change_membership_level', 'my_send_pmpro_confirmation_emails_from_dashboard', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Send Members a confirmation email when admins change their membership level." at Paid Memberships Pro here: https://www.paidmembershipspro.com/send-members-a-confirmation-email-when-admins-change-their-membership-level/