Skip to content

Instantly share code, notes, and snippets.

@femiyb
Last active November 13, 2019 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save femiyb/62a2b8f10100e7afc93d6768a6ef5ef2 to your computer and use it in GitHub Desktop.
Save femiyb/62a2b8f10100e7afc93d6768a6ef5ef2 to your computer and use it in GitHub Desktop.
Require discount code on checkout
<?php
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 = 4 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 == 4 && 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