Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Forked from femiyb/require_discount_code.php
Last active June 9, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dparker1005/cd47c20d751d90015a86f44790134793 to your computer and use it in GitHub Desktop.
Save dparker1005/cd47c20d751d90015a86f44790134793 to your computer and use it in GitHub Desktop.
Require discount code on checkout
<?php
// Copy from below here
/*
* Require that a user use a discount code when reigstering for specific levels.
*/
function my_pmpro_registration_checks_require_code_to_register( $pmpro_continue_registration ) {
$restricted_levels = array( 1, 3 ); // Levels 1 and 3 require a discount code to register
global $discount_code, $pmpro_level;
if( empty( $discount_code ) && in_array( $pmpro_level->id, $restricted_levels ) ) {
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