Last active
March 4, 2019 19:27
-
-
Save messica/7d3436b18adf1b18116d to your computer and use it in GitHub Desktop.
Give users permanent level after x successful payments.
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 permanent level after x successful payments. (Fake "billing cycle limits") | |
*/ | |
function my_pmpro_after_change_membership_level( $level_id, $user_id ) { | |
global $wpdb; | |
// change number of payments here | |
$payments = 10; | |
// are they expiring? | |
if ( $level_id == 0 ) { | |
// get old level | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( $user_id ); | |
$old_level_id = $order->membership_id; | |
// 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 level back 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, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment