Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 16, 2021 23:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save strangerstudios/5573829 to your computer and use it in GitHub Desktop.
Save strangerstudios/5573829 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.
/*
Only let level 1 members sign up if they use a discount code.
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 bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;
//level = 1 and there is no discount code, then show an error message
global $pmpro_level, $discount_code;
//if($pmpro_level->id == 1 && (empty($discount_code) || trim(strtoupper($discount_code)) != "REQUIRED_CODE_IN_UPPERCASE")) //use this conditional to check for a specific code.
if($pmpro_level->id == 1 && 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");
@petervangorder
Copy link

How/Where do people enter their discount code at registration?
The above code checks for a Discount Code, but I'm not understanding how/where someone enters their discount code or where the code is that creates the field to allow them to enter it.

@uswine
Copy link

uswine commented Jan 29, 2015

same comment as above

@kealapono
Copy link

@uswine & @petervangorder you'll also need to create a discount code. Last item under the "Membership" tab labeled "Discount Codes" 😄

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Require a Discount Code to Checkout for a Certain Level" at Paid Memberships Pro here: https://www.paidmembershipspro.com/require-a-discount-code-to-checkout-for-a-certain-level/

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