Created
September 20, 2019 08:36
-
-
Save nfsarmento/f2102bc79e8e9b4f012464214c23e5ec to your computer and use it in GitHub Desktop.
Gravity Forms - product field "user defined" price max value
This file contains 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
// Form product field validation - max price of £500 | |
// gform_field_validation_3_9 the 3 is your form ID and the 9 is your field ID | |
add_filter( 'gform_field_validation_3_9', 'price_custom_validation', 10, 4 ); | |
function price_custom_validation( $result, $value, $form, $field ) { | |
//change value for price field to just be numeric (strips off currency symbol, etc.) using Gravity Forms to_number function | |
//the second parameter to to_number is the currency code, ie "USD", if not specified USD is used | |
$number = GFCommon::to_number( $value, '' ); | |
if ( $result['is_valid'] && intval( $number ) > 500 ) { | |
$result['is_valid'] = false; | |
$result['message'] = "Maximum donation is £500. Please contact test@test.org to make a larger donation and for further information"; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment