Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Forked from strangerstudios/pmpro_cancelled_level.php
Last active March 10, 2022 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pbrocks/f404072cf11b681b4857ab4ec086ad4a to your computer and use it in GitHub Desktop.
Save pbrocks/f404072cf11b681b4857ab4ec086ad4a to your computer and use it in GitHub Desktop.
Move PMPro members to another level when they cancel.
<?php
/**
* By default cancelled members are changed to level 0. This recipe changes that behavior to give them a "cancelled" level that
* you have created for that purpose. Can be used to downgrade someone to a free level if they cancel.
*/
/**
* [pmpro_after_change_membership_level_default_level description]
*
* @param [type] $level_id [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
function pmpro_after_change_membership_level_default_level( $level_id, $user_id ) {
// if we see this global set, then another gist is planning to give the user their level back
global $pmpro_next_payment_timestamp;
if ( ! empty( $pmpro_next_payment_timestamp ) ) {
return;
}
if ( $level_id == 0 ) {
// cancelling, give them level 1 instead
pmpro_changeMembershipLevel( 1, $user_id );
}
}
add_action( 'pmpro_after_change_membership_level', 'pmpro_after_change_membership_level_default_level', 10, 2 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Change Membership Level on Cancellation or Expiration" at Paid Memberships Pro here: https://www.paidmembershipspro.com/change-membership-level-on-cancellation-or-expiration/

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