Created
June 28, 2019 23:30
-
-
Save messica/978727fbc3b908a2f824900e49cc0764 to your computer and use it in GitHub Desktop.
Don't allow renewal for same level if user has an active subscription.
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 | |
/** | |
* Don't allow renewal for same level if user has an active subscription. | |
*/ | |
// Hide the Renew link. | |
function hide_renewal_links_for_some_levels($r, $level) { | |
// Get user's last order. | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( null, 'success', $level->id ); | |
if ( ! empty( $order ) && ! empty( $order->subscription_transaction_id ) ) { | |
$r = false; | |
} | |
return $r; | |
} | |
add_action('pmpro_is_level_expiring_soon', 'hide_renewal_links_for_some_levels', 10, 2); | |
// Prevent registration and display error message when checking out. | |
function my_pmpro_registration_checks( $continue ) { | |
global $pmpro_level; | |
// Get user's last order. | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder( null, 'success', $pmpro_level->id ); | |
if ( ! empty( $order ) && ! empty( $order->subscription_transaction_id ) ) { | |
$continue = false; | |
pmpro_setMessage( 'You must wait until your membership expires before renewing.', 'pmpro_error' ); | |
} | |
return $continue; | |
} | |
add_filter( 'pmpro_registration_checks', 'my_pmpro_registration_checks' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment