Paid Memberships Pro: Email the Admin When a Member Cancels
Emails you right away when a member cancels their membership, with the level they left, so you can ask why or offer help.
Opens WPIDE on
Code
if ( ! function_exists( 'pmpro_getLevel' ) ) {
return;
}
add_action( 'pmpro_after_change_membership_level', function ( $level_id, $user_id, $cancel_level ) {
if ( 0 !== (int) $level_id || empty( $cancel_level ) ) {
return;
}
$user = get_userdata( $user_id );
$level = pmpro_getLevel( is_object( $cancel_level ) ? $cancel_level->id : $cancel_level );
if ( ! $user ) {
return;
}
wp_mail(
get_option( 'admin_email' ),
sprintf( 'Cancellation: %s', $user->display_name ),
sprintf( "%s (%s) cancelled their \"%s\" membership on %s.", $user->display_name, $user->user_email, $level ? $level->name : 'membership', wp_date( get_option( 'date_format' ) ) )
);
}, 10, 3 );
Notes
Only cancellations are reported (moving to level 0), not upgrades or downgrades between levels.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.