Forked from strangerstudios/my_pmpro_registration_checks.php
Last active
July 19, 2024 15:25
-
-
Save kimwhite/f6e43adc15a5e28ee777be30783a7560 to your computer and use it in GitHub Desktop.
Require a certain level before registering for another level with Paid Memberships Pro.
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 // do not copy this line. | |
/** | |
* This recipe Requires a certain level before registering for another level. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
* Edit lines 19,20,33,34 with your site levels. Update message line 22 | |
*/ | |
function my_pmpro_checkout_before_form() | |
{ | |
global $pmpro_level, $current_user; | |
// Check if the user is trying to checkout for the specific levels and doesn't have the required level | |
if( | |
($pmpro_level->id == 2 && !pmpro_hasMembershipLevel(1, $current_user->ID)) || | |
($pmpro_level->id == 3 && !pmpro_hasMembershipLevel(8, $current_user->ID)) | |
) { | |
pmpro_setMessage("You must fill out your Student member profile before registering for this course.", "pmpro_error"); | |
} | |
} | |
add_action("pmpro_checkout_before_form", "my_pmpro_checkout_before_form"); | |
function my_pmpro_registration_checks($okay) | |
{ | |
global $pmpro_level, $current_user; | |
// Check if the user is trying to checkout for the specific levels and doesn't have the required level | |
if( | |
($pmpro_level->id == 2 && !pmpro_hasMembershipLevel(1, $current_user->ID)) || | |
($pmpro_level->id == 3 && !pmpro_hasMembershipLevel(8, $current_user->ID)) | |
) { | |
$okay = false; | |
} | |
return $okay; | |
} | |
add_action("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