Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created March 28, 2016 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strangerstudios/44e4cccb206210e248fa to your computer and use it in GitHub Desktop.
Save strangerstudios/44e4cccb206210e248fa to your computer and use it in GitHub Desktop.
Don't allow early renewals for certain levels with Paid Memberships Pro.
/*
Don't allow early renewals for certain levels.
Change the level IDs in the $pmpro_non_renewal_levels global array, then
add this code to your active theme's functions.php or a custom plugins.
*/
//define levels in global
global $pmpro_non_renewal_levels;
$pmpro_non_renewal_levels = array(1,2,3); //change this to the level IDs of the levels you don't want users to renew for
//hide the renew link
function hide_renewal_links_for_some_levels($r, $level) {
global $pmpro_non_renewal_levels;
if(in_array($level->id, $pmpro_non_renewal_levels))
$r = false;
return $r;
}
add_action('pmpro_is_level_expiring_soon', 'hide_renewal_links_for_some_levels', 10, 2);
//redirect from checkout page to the membership account page
function redirect_non_renewing_levels() {
global $pmpro_non_renewal_levels;
//make sure pmpro is active
if(!function_exists('pmpro_hasMembershipLevel'))
return;
//if we're checking out, redirect to account page
if(!is_admin() && !empty($_REQUEST['level']) && in_array($_REQUEST['level'], $pmpro_non_renewal_levels) && pmpro_hasMembershipLevel(intval($_REQUEST['level']))) {
wp_redirect(add_query_arg('norenewal', '1', pmpro_url('account')));
exit;
}
}
add_action('template_redirect', 'redirect_non_renewing_levels');
//show message on the account page
function the_content_add_non_renewal_message($content) {
global $pmpro_pages;
if(!empty($pmpro_pages) && is_page($pmpro_pages['account']) && !empty($_REQUEST['norenewal']))
$content = "<p><strong>You must wait until your membership expires before renewing.</strong></p>" . $content;
return $content;
}
add_filter('the_content', 'the_content_add_non_renewal_message');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment