Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/51ebce0093d5f892a762 to your computer and use it in GitHub Desktop.
Save greathmaster/51ebce0093d5f892a762 to your computer and use it in GitHub Desktop.
Place a PMPro member in another level and give them a new expiration date when they cancel.
/*
When users cancel (are changed to membership level 0) we give them another "cancelled" level. Can be used to downgrade someone to a free level when they cancel.
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
if($level_id == 0)
{
//cancelling, give them level 1 instead
$expiry_level_id = 1;
$level = pmpro_getLevel($expiry_level_id);
//give them an expiry date one year from today.
$level->enddate = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " + 365 day"));
pmpro_changeMembershipLevel($level, $user_id);
}
}
add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment