Created
April 14, 2015 16:12
-
-
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.
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
/* | |
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'); |
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
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!