Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created September 20, 2019 08:36
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 nfsarmento/f2102bc79e8e9b4f012464214c23e5ec to your computer and use it in GitHub Desktop.
Save nfsarmento/f2102bc79e8e9b4f012464214c23e5ec to your computer and use it in GitHub Desktop.
Gravity Forms - product field "user defined" price max value
// 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