Skip to content

Instantly share code, notes, and snippets.

@MaximilianoRicoTabo
Last active January 2, 2024 19:59
Show Gist options
  • Save MaximilianoRicoTabo/76c3d5006e049885e48455b807f113fc to your computer and use it in GitHub Desktop.
Save MaximilianoRicoTabo/76c3d5006e049885e48455b807f113fc to your computer and use it in GitHub Desktop.
Validate after checkout the discount code is valid
<?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