Skip to content

Instantly share code, notes, and snippets.

@messica
Created June 28, 2019 23:30
Show Gist options
  • Save messica/978727fbc3b908a2f824900e49cc0764 to your computer and use it in GitHub Desktop.
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.
<?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