Gravity Forms can be a great ecommerce solution if you don’t have enough products to make it worth while to set up a full shopping cart system. If you want to learn more about that, read my Gravity Forms eCommerce tutorial. But if you’re already rocking GF and have set up your products and just need a way to make sure you don’t sell something you don’t have in stock, read on.
There are two ways to limit product quantities with Gravity Forms.
Method 1: Code
You can simply add some code to your functions.php file:
new GWLimitBySum( array( 'form_id' => 363, 'field_id' => 2.3, 'limit' => 2, 'limit_message' => 'Sorry, there are no more tickets!', 'validation_message' => 'You ordered %1$s tickets. There are only %2$s tickets left.', 'approved_payments_only' => false, 'hide_form' => false ) );
Note: you’re going to need to update these parameters with the ones that pertain to you. Read the full tutorial from Gavity Wiz to find out more.
Method 2: Plugin
If you want an easier interface to work with, you can simply download the Gravity Forms Quantity Limiter plugin. While this is a great plugin, I couldn’t find any tutorials on how to use it, so I’m going to show you what to do here.
How to set up Gravity Forms Quantity Limiter Plugin
1. Simply install the plugin just like you would any other. It’s in the WordPress repository, so simply go to Plugins > Add New and search for it by name. Then click install and then activate it.
2. Once you’ve installed it, you’ll notice a new link under Forms in your left hand menu on your dashboard called Quantity Limits.
3. From there, you will need to create a new quantity limit for each item, so click “Add New” at the top of this page. Once you click Add New, you will be able to chose the form you want to affect, then the product, then the quantity you want to limit the item to. You will also see that you can customize the text that is show in different situations.
In my example above, you’ll notice I’ve already created two limits – both for my Online Registration form. The first limits the product I’m calling Visionary to one item. The second limits the product I’m calling Executive to two items. I haven’t had any sales yet, so the column for Current Amount is empty.
The bottom message that you can customize is your reminder message, and that will show on the form until that object is sold. For example, for my product I have a “Visionary Sponsorship” available, but there can be only one of these sponsors. So, for my “reminder message” in the form above, I have put the text “We will have only one Visionary Sponsor”, and that shows at the bottom of my product under the description I have added.
One down side is that customers will still be able to choose any amount, but will be given an error message when they try to checkout with more items than allowed. So, for my “validation message” I put “Thanks for choosing our Visionary Sponsorship. There will only be one Visionary Sponsor.” and you can see that it shows up here when I try to check out.
The last message you are able to customize is the Sold out message, and that is what will show when people can no longer purchase an item.
But that’s all there is to it. The plugin makes doing this pretty easy. Keep in mind that it will restrict any items that have entries in the back end, so if you have some people who submit a form, but then didn’t pay, make sure to trash those entries so they don’t keep other people from buying.