Last active
March 4, 2019 21:34
-
-
Save LMNTL/3dd55795a8dd129009f05ca6bdf76247 to your computer and use it in GitHub Desktop.
Give users a new level after x successful payments at a specific previous level - based on https://gist.github.com/messica/7d3436b18adf1b18116d#file-my_pmpro_after_change_membership_level-php-L14-L17
This file contains 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 | |
/* | |
* Give users a new level after x successful payments at another level. | |
*/ | |
function my_pmpro_after_change_membership_level($level_id, $user_id, $cancel_level) | |
{ | |
global $wpdb; | |
// change number of payments here | |
$payments = 10; | |
// change to the ID of the level the users need to make payments at | |
$previous_level = 2; | |
// get old level | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder($user_id); | |
$old_level_id = $order->membership_id; | |
// are they expiring? | |
if( $level_id == 0 && $cancel_level == $previous_level ) | |
{ | |
// count successful orders for this level | |
$sql = "SELECT COUNT(id) FROM $wpdb->pmpro_membership_orders WHERE user_id=$user_id AND status='success' AND membership_id=$old_level_id"; | |
$count = $wpdb->query($sql); | |
// give them the new level if they have enough payments | |
if($count >= $payments) | |
pmpro_changeMembershipLevel($old_level_id, $user_id); | |
} | |
} | |
add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment