-
-
Save kimwhite/fb4f319bd21095ab91fce60170cba359 to your computer and use it in GitHub Desktop.
Paid Memberships Pro customization to only let members of a certain level checkout if a discount code was used.
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
<? // Updated for Multiple Levels. | |
/* | |
Require a discount code for specific membership levels. | |
Place this code in your active theme's functions.php or a custom plugin. | |
*/ | |
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration) | |
{ | |
// Only proceed if registration checks have passed so far | |
if (!$pmpro_continue_registration) { | |
return $pmpro_continue_registration; | |
} | |
// Define the levels that require a discount code | |
$levels_require_discount = array(1, 2, 3); // Replace with the IDs of the levels that require a discount code | |
// Access the global variables for level and discount code | |
global $pmpro_level, $discount_code; | |
// Check if the current level requires a discount code and if the discount code is empty | |
if (in_array($pmpro_level->id, $levels_require_discount) && empty($discount_code)) { | |
pmpro_setMessage("You must use a valid discount code to register for this level.", "pmpro_error"); | |
return false; | |
} | |
return $pmpro_continue_registration; | |
} | |
add_filter("pmpro_registration_checks", "my_pmpro_registration_checks_require_code_to_register"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment