Last active
January 2, 2024 19:59
-
-
Save MaximilianoRicoTabo/76c3d5006e049885e48455b807f113fc to your computer and use it in GitHub Desktop.
Validate after checkout the discount code is valid
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 | |
/** | |
* Add a custom validation to the checkout page. | |
* | |
* @param bool $pmpro_continue_registration | |
*/ | |
function my_custom_validations( $pmpro_continue_registration ) { | |
if ( $pmpro_continue_registration ) { | |
// Check if the user has the level needed. | |
if ( ! empty( $_REQUEST['discount_code'] ) && $_REQUEST['discount_code'] == 'F37910BEB5' && ! pmpro_hasMembershipLevel( '6' ) ) { | |
pmpro_setMessage( __( "Invalid discount code.", 'paid-memberships-pro' ), "pmpro_error" ); | |
return false; | |
} | |
} | |
return $pmpro_continue_registration; | |
} | |
add_action( 'pmpro_registration_checks', 'my_custom_validations' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment