1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Number field validation
  1. Home
  2. Knowledge Base
  3. Troubleshooting
  4. Number field validation

Number field validation

If you have set a minimum or maximum value for your number field, it will try to validate this whether or not the field is required.

This means that if you have entered a minimum of 5 and the user leaves the field empty, there will still be a validation error if the user tries to add the product to the cart – even though the field is not required.

To ensure that number fields can be left empty even if they have a minimum or maximum value, and prevent validation on a non-required number field, add this to your functions.php file or snippets file:

// Add this if you want to prevent non-required number fields from validating min or max values
add_filter( 'pewc_only_validate_number_field_value_if_field_required', '__return_true' );

Was this article helpful?

Need More Support?

If you can't find the answer that you're looking for, then please use the link below to raise a support ticket.
Contact Support

Related Articles