Last active
November 15, 2018 13:50
-
-
Save kimcoleman/aaf17b3c42593c7cea6b039d9e0ff05c to your computer and use it in GitHub Desktop.
Custom cancellation for use sabbella
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom downgrade on membership cancellation code for sabbella ticket. | |
*/ | |
function sabbella_pmpro_after_change_membership_level_downgrades( $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; | |
} | |
// Are they cancelling? | |
if ( $level_id == 0 ) { | |
// Check if they are cancelling level 4, 3, or 2. | |
global $wpdb; | |
$last_level_id = $wpdb->get_var( "SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user_id . "' ORDER BY id DESC" ); | |
if ( $last_level_id == 4 ) { | |
pmpro_changeMembershipLevel( 2, $user_id ); | |
} elseif( $last_level_id == 3 ) { | |
pmpro_changeMembershipLevel( 2, $user_id ); | |
} else { | |
pmpro_changeMembershipLevel( 1, $user_id ); | |
} | |
} | |
} | |
add_action( 'pmpro_after_change_membership_level', 'sabbella_pmpro_after_change_membership_level_downgrades', 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment