How to Set a Default Product Quantity in Gravity Forms

Nov 12, 2021

3 Min. Read

Share URL

This page may contain affiliate links. Please read my disclaimer for more information.

I recently had a Gravity Forms user ask the following question: “How can I add a “0” in the quantity field by default.”

Out of the box, Gravity Forms does not support setting a default quantity for the quantity field available in the Product field, by default the quantity box is empty.

This can be problematic, especially if you have multiple product fields in your form that are required. The user may think leaving the quantity field empty is the same as 0, but an empty quantity field will cause a validation error.

If you can populate the quantity field by default with any number, in this case, the request is to set the quantity to zero, you can avoid the validation errors and in some cases maybe even ensure the user is making the appropriate selections.

There are two ways of accomplishing this.

Option 1: Using the Quantity Field (no code)

If you’re confused, let me clear this up for you.

Gravity Forms has a stand-alone Quantity field that can be mapped to your Product fields so that you can disable the quantity field in the Product field.

There, that should have cleared it up 🤔.

But just in case you’re still (or more confused), here are some steps to take:

  1. Go to Pricing Fields Section
  2. Drag the Quantity Field into your form
  3. Click the Product field and check “Disable quantity field” (in the General settings)
  4. Click the new quantity field to open the General settings
  5. Under “Product Field Mapping” Select the product you want to map the field too

Once the new Quantity field is mapped you can set the default quantity by using the Default Value option in the Advanced field settings.

  1. Click on the Quantity Field
  2. Go to the Advanced tab
  3. Enter a number in the Default Value field

See it in action:

Option 2: Using a Code Snippet

Even though there is a little bit of code involved, you might find that this solution is easier and more convenient. It will allow you to use the quantity field that is in the Product field reducing the number of fields in your form.

Not to mention, because the code snippet is provided, you only need to cut and paste to get this magic to work!

  1. Copy the code below
https://gist.github.com/chrisegg/c40c4c761e2262a086dc9bc0d45d7b11

Where to put this code? You will need either edit your functions.php file and paste this code there, or use a functionality plugin like WPCodeBox (recommended).

  1. Paste it into your functions.php file or functionality plugin (I will be using WPCodeBox for this)
  2. Click your Product field to open the settings
  3. Go to the Advanced tab
  4. Check the box “Allow field to be populated dynamically”
  5. Add this parameter “default_quantity” to the Quantity field

The Wrap Up

That’s it. You should now be able to set the default quantity of your product field. My only suggestion is that you use the solution that is best for you.

If you have any issues or questions, please feel free to use the comments below.

Photo of author
About the Author
Chris Eggleston
Husband. Father of 4. Grandpa of 2. Chief Problem Solver exploring business systems, technology, AI & faith — helping people solve real problems. @mantiswp @chrisegg

Support Chris - Donate $5

Gravity Wiz Add-Ons

Advertisement

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Post

How to Secure a Digital Broadcast Page with Gravity Forms Submit to Access Add-On

Live events and webinars are powerful ways to connect with your audience, but hosting them directly on your WordPress site...

Oct 3, 2025

4 min. read

Step-by-Step Guide: Sending a Gravity Forms Notification to the User

Gravity Forms notification feature allows you to send emails to users automatically when they submit a form. This is useful...

Mar 20, 2025

5 min. read

Gravity Forms Multi-Date Picker

Gravity Forms is a powerful form builder, but you might occasionally find some limitations. For example, the date picker field...

Nov 13, 2024

4 min. read

How to Migrate From WS Forms to Gravity Forms: A Step-by-Step Guide

Migrating from WS Forms to Gravity Forms can seem daunting, but with the right approach, it can be a smooth...

Oct 26, 2024

4 min. read

How to Connect Gravity Forms to SendFox: A Step-by-Step Tutorial

This tutorial will walk you through connecting Gravity Forms to SendFox and ensuring your contacts are added to your email marketing...

Oct 16, 2024

5 min. read

How to: Gravity Forms BMI Calculator

Many people don’t realize that the calculation feature is built into the Gravity Forms core plugin and is available for...

Oct 10, 2024

4 min. read