Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greathmaster/8ae1a008c6af1d2e0bdb to your computer and use it in GitHub Desktop.
Save greathmaster/8ae1a008c6af1d2e0bdb to your computer and use it in GitHub Desktop.
Assign different levels to members if cancelling or expiring
/*
* When users cancel, assign them a level based on their status. See list of available status':
* http://www.paidmembershipspro.com/2015/03/statuses-available-in-the-pmpro_memberships_users-table-updated-member-history-add-on/
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
global $wpdb;
if($level_id == 0)
{
$row = $wpdb->get_row("SELECT `status` FROM $wpdb->pmpro_memberships_users WHERE `user_id` = $user_id AND (`status` LIKE 'cancelled' OR `status` LIKE 'admin_cancelled' OR `status` LIKE 'expired') ORDER BY `enddate` DESC LIMIT 1");
if($row != null)
{
//put 'admin_cancelled' and 'cancelled' into one level
if($row->status === 'admin_cancelled' || $row->status === 'cancelled')
{
$level_id = 25; //cancelled level id
}
if($row->status === 'expired')
{
$level_id = 24; //expired level id
}
}
pmpro_changeMembershipLevel($level_id, $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