Gravity Forms provides the ability to set a minimum per field when using a separate Quantity field but what about a minimum quantity for the entire order? This snippet can help!
View this code snippet on GitHub.An added bonus! This snippet also allows you to specify a minimum quantity for a single product field without requiring a separate Quantity field.
How do I install this snippet?
Click the “Copy to Clipboard” link at the bottom of the snippet then paste the code into your theme’s functions.php file. Abracadabra!
Do I need to configure this snippet to work with my form?
Yes! This snippet has four bits to customize.
- Update the
86
in the filter namegform_validation_86
to the ID of your own form. - Update the
$min_qty
variable to the minimum quantity your form should require. - Update the
$min_qty_message
variable to the validation message which should be displayed if the minimum quantity is not met. Use%1$d
to populate the minimum number of tickets require. Use%2$d
to populate the number of tickets the user must add to their order to meet the minimum. The actual values will be populated when the form is validated.Minimum Quantity Validation Message
- If you wish to limit the minimum quantity requirement to a specific set of fields, enter the IDs of these fields in the
$min_qty_fields = array();
array like so:$min_qty_fields = array(3, 5);
. Otherwise, simply leave this variable as is.
Ready to go!
And that’s it; you’re all ready to go. If you use this snippet, we’d love to see it live on your site. Consider sharing a link to your implementation in the comments.
Need to set a maximum order quantity? Let us know and we’ll show you how to modify this snippet to do it!