Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/135b29b47ebf04c3d094773625ff4707 to your computer and use it in GitHub Desktop.
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.
/**
* 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 );
@laurenhagan0306
Copy link

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/

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