Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created April 14, 2015 16:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save strangerstudios/d417b530e77c2f8f76fc to your computer and use it in GitHub Desktop.
Save strangerstudios/d417b530e77c2f8f76fc to your computer and use it in GitHub Desktop.
Redirect away from the checkout page if you don't have a required level with Paid Memberships Pro.
/*
Redirect away from the checkout page if you don't have a required level.
*/
function my_template_redirect_upgrade()
{
global $pmpro_pages, $pmpro_level;
if(empty($pmpro_pages))
return;
if(is_page($pmpro_pages['checkout']) && $pmpro_level == 2 && !pmpro_hasMembershipLevel(1)) //change ids checked here
{
wp_redirect(site_url('page-explaining-you-need-level-1-first')); //change url here
exit;
}
}
add_action('template_redirect', 'my_template_redirect_upgrade');
@tenkabuto
Copy link

Line 11 only worked for me once I changed the following

$pmpro_level == 2

to

$pmpro_level->id == 2

I figured this out when referring to https://gist.github.com/strangerstudios/5573829

Thank you for this Gist, nevertheless!

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Redirect Away from Checkout if User Doesn’t Meet Membership Requirements" at Paid Memberships Pro here: https://www.paidmembershipspro.com/redirect-away-from-checkout-if-user-doesnt-meet-membership-requirements/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment