A user on the Gravity Forms Support Forums posted today asking if it were possible to setup a shipping fee that was only applicable if the order total was over a certain amount. As of Gravity Forms v1.6.4, this is now possible!
The form total (aka order total) may not be available for conditional logic; however, Number fields are and as of Gravity Forms v1.6.4, Number fields have been enhanced to support calculations. This tutorial will demonstrate how Gravity Form calculations work and how you can use this new feature to setup conditional shipping.
Calculated Form Total
I’m going to assume you already have your form setup with products, options, etc. The next step will be to add a Number field. Open up the settings for this field and click “Enable Calculation” to reveal the “Formula” textarea.

Now comes the tedious part.
In order to get the form total you will need to calculate each product’s total and then add them together. To get a product’s total, you must add the product price to the product options price and then multiply this sum by the product quantity. You then add up each product’s total to get the form total.
-
Single Product with a Single Option
(Product Price + Option Price) * Product Quantity
-
Single Product with Multiple Options
(Product Price + Option #1 Price + Option #2 Price) * Product Quantity
-
Multiple Products
((Product #1 Price + Option #1 Price) * Product #1 Quantity) + ((Product #2 Price + Option #2 Price) * Product #2 Quantity)
For simple forms this is no problem. For larger forms… have fun.
Shipping Conditional Logic
Now that you have your Number field setup as a calculation, you’re ready to configure your Shipping field’s conditional logic. For this example, we’ll configure the Shipping field to only display if the “Calculated Form Total” is greater than 10.

Hiding the Calculated Form Total
So you’ve tried it out and it’s amazing, but… you probably don’t want to leave your Calculated Form Total field visible for users to see. Just add “gf_hidden” as a CSS class for this field on the “Advanced” tab. Presto strango!
Summary
That’s a wrap! What do you think? Will you use this technique on your own forms?
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 47+ essential add-ons for Gravity Forms with support you can count on.
Hi David, I have a question and I have tried searching solution. But I was not able to find any solution so now on your mercy :P
I don’t want to calculate shipping charges on product level, but in the cart where shipping charges will be calculated during checkout. Simple because many products can be delivered in a single shipment. I am pretty new to gravity forms, so to me it seems like ‘gravity form’ with ‘woocommerce gravity form product addon’ do not provide such option. Please enlighten me
Hey Deepak, this only works per form submission. You’ve have to find an alternate solution if you’re trying to do it to the WooCommerce cart.
Hi,
I use Product addon with conditionnal logic as follow :
I sell products on wholesale, but client can chose “Sample” with a radio button.
If he choses sample, he gets a shipping fee of $2
if he buys the product ( starts with 30 products minimum ) the shipping fee is more, but it depends on the countries he is from so i’m using the woocommerce Local Delivery and International Delivery
When I use the method you explain, the $2 fees adds up with thr local delivery fee… which i dont want.
How to do that ?
Hi Jerem, if you have specific options that should dictate the shipping pricing, you can base the conditional logic on whether those options are selected rather than the form total.
I have an order form for wines, where the shipping is calculated on a quantity basis, in increments of 12 bottles. So the shipping is not dependent on the order total, but rather total quantity of items. How would one go about getting this calculation, if at all possible?
You can get the product count with this snippet:
https://gist.github.com/spivurno/11443098
It will populate the number of products currently selected and then you can use that field merge tag in your calculation. :)
Using the same logic, I want to add an administrative fee(replace shipping)- once the order hits a certain amount. So, is there an easier way than how the above explains. Is there a way to create a rule- if the amount reaches $2,000 add $50 and call it an admin fee?
You can see current form here http://sruins.com/circus-producers-association/
You can use the Subtotal Merge Tag to populate a number field with the current total. Then use GF conditional logic to show/hide a product field with your admin fee.
Hi David,
I have stumbled across your site as the last chance saloon, before I junk WordPress and Gravity Forms for my website.
You seem so helpful to others, perhaps you can point me to how I can do what I need, I have tried WP and GF forums and not one reply.
I have a site which is going to allow users to order A4, A3, A2, A1 and A0 + Custom Size print online. There are price breaks for each A size with different unit costs, so 1-5 £3.50, 6-10 £3.25, 11-25 £3.00, 26-50 £2.75 and 51+ £2.50 each A4.
So the user selects A4-A0 size types in their quantity and the total is shown plus hopefully the unit cost.
If they pull down further to Custom Size they can input Width and Height when those boxes conditionally appear, type in the sizes to get a calculated unit cost.
Once chosen they have the opportunity to upload their artwork with the order.
I have tried all this in woocommerece and adding a measurement calculator add on, that did not work. I then was pointed to Gravity Forms and told it can be done there, so I purchased but have spent days and days trying to get it to do the above and I must be doing something wrong.
Any pointers as to what parts I am supposed to use and how would really be appreciated.
Thanks
Nick
Hi Nick, this is possible with GP Conditional Pricing. Take a look at the documentation and demo and let me know if you have any questions.
Sorry, did not see reply button so am adding to thread ;-)
Hi David,
Thanks for the reply. So the purchase of perks would allow me to create a form which does all what I need as set out in my original question?
Sorry, but I would need some pointers as to how to do this. I am very disheartened with WP after spending weeks trying to sort this out and purchasing over five add on’s.
If I can do all this with your perks then I will be very happy.
How will the form integrate with the theme cart and I also need that file uploader which is triggered after payment.
Basically, Choose Poster size, or add in Custom size, Prices displayed and then add quantity needed which shows price plus VAT split. After the customer goes to pay they are prompted to upload print file.
That’s it.
Thanks
Nick
Gravity Perks (with the GP Conditional Pricing perk) would let you handle just the ability to price the product by the quantity ordered and by a calculated width and height. Everything else would be covered by either Gravity Forms or WooCommerce via the WooCommerce Gravity Forms Product Add-ons plugin.
Hi David,
I have looked at the demo and docs on the page. Is there a demo area where this is working which I can set up a form please. Your example although showing the principle is quite different from my specifics. If I can try an online form that would be great. The suggestion hopefully will sort out the price breaks on the A sizes. How would I go about the Custom Size W x H input fields in a Gravity Form.
Thanks
Nick
Hi David,
I would like to use heb calculation option as a commission calculator. Lets say someone want to sell something for €10 and writes €10 as selling price. Is it possible to automatically calculate my commission of for example 10% = €1? So that my set commission automatically appearce in a row next to the price the seller provided? If so, how? I hope you can help. Thank you so much in advance!
You can set this up as a Number field with the calculation feature enabled and the formula to calculate your commission. You can then position this field to appear wherever you’d like via CSS.
Thank you so much! That’s amazing!
Can you please be so kind to tell me which code I need to use if (For example) someone who writes down an amount between €0-€1000 had to pay me 15% commission.
Also which code do I have to use if someone writes €100 and the commissie bepens on the question they answerd before.
I hope you can help me out.
Check out this article for more details. The demo includes a formula pretty close to what you need.
https://gravitywiz.com/subtotal-merge-tag-for-calculations/
Hi,
It works great, however I’m using your better-pre-submission-confirmation and the number field is shown there even though I used gf_hidden class.
How can I hide it from there?
If you’re using the {all_fields} merge tag on the pre submission HTML, check out this snippet for including/excluding fields form the {all_fields} merge tag: https://gist.github.com/richardW8k/6947682
Hi I need some help. I have a requirement. If my item total is till rs 60 i want shipping to be rs 60, and if it is beyond rs 60, i want my shipping to be rs 40. How do I do this. I tried the method listed above but it only shows one value for the shipping field. Is it possible to dynamically change the shipping fields value based on item total. Please take a look at the form. Some help is much appreciated.
Hi Sainik, I don’t know of a simple way to accomplish this.
@Sainik @David
Was looking for a similar solution for this where if price A, show shipping_A, if price B, show shipping_B.
No known way to accomplish this yet.
Would still say that this is by far one of (if not, the most) elegant solutions around. Thanks again David!
I asked Richard at Gravity Forms and he had a solution. To quote Richard “This is possible by using a calculated number field, shipping field and a HTML field containing a script using the gform_calculation_result hook. We don’t have an example on the demo site but I do have an example on my test site: http://gravitydev.wawrzyniak.me/calculated-shipping/ The shipping calculation field on that form would normally be hidden.” This solves my problem. This might solve Daniel’s problem too. Still thanks a lot David for the Sub Total Merge. :)
You’re a godsend! My turn to try to get it to work on my form. :)
http://singaporeotah.com
Glad to help, Daniel!
Hi guys,
I’m still kind of confused by all these.
Let say if I have a single $10 product weigh 1kg. The shipping cost would be $2.
And what if a customer ordered 2 products, the shipping should now cost $4.
So instead of $10 x 2 + $2 = $22, I want it to be $10 x 2 + $4 = $24.
Any idea how to calculate this with GForm?
Thanks in advance!
Ok here is how I got my equation to work. Product enable caculation {Option:8}{Number:7}{Quantity:4}
By doing it this way the Total field becomes the Product field and the total field is not used.
Thanks again for all the useful insight in to how Gravity Forms works. JC
Hi David and all viewers, I am new to gravity Forms and loving it so far. Great insight in to how the whole thing works. Thanks
Now I have a question on how calculate a form that has 3 parts on one page and one product.
(product+option)(quanty1)(quanty2)==(total)
the (quanty1) field is really size. and (quanty2) is how many. do I use a (custom calculation field) instead of (Total) Or do I use Allow field to be populated dynamically then calculate total after?
any help here would be nice. Thanks and multi readers also want to know also. Thanks again and keep up the great work. Loving it. JC
Hi David,
I’m looking at your snippet here: http://pastie.org/5512619
I have a few number calculation fields – one is called CalculatedTotal – so how would I hide this in the emails?
Thanks
Hi Keely, my comment on this article will demonstrate how to hide any field from the {all_fields} merge tag by field ID:
https://gravitywiz.com/better-pre-submission-confirmation/#comment-9700
Beautiful – that one worked! Thanks for all your help :)
My pleasure. :)
I just have a set of products and I tried this but it didn’t work. I don’t have options or quantities – what to do?
Thanks
Hi Keely, you might be interested in this new article:
https://gravitywiz.com/subtotal-merge-tag-for-calculations/
It allows you to use a {subtotal} merge tag so you don’t have to manually figure out the equation and correct merge tags. It’ll save you a lot of time. :)
Thanks for that David – added the snippet into my functions.php but no subtotal merge field. Oh well. Back to the drawing borad.
Make that drawing board … lol
Not sure why you wouldn’t be seeing the {subtotal} merge tag in the drop down; however, as long as the code is in place, you can just add the merge tag manually:
{subtotal}
Hi David,
Thanks for your great tutorial!
How can we hiding the calculated Form Total, when using the merge tag: {all_fields}?
Option {all_fields:noadmin,nohidden} doesn’t work.
Hi Don, give this a shot: http://pastie.org/5512619
Hi David, can radio options each have a price?
for example i have a single product field (price & quantity) and two radio buttons Menu 1 and Menu 2. If a user selects Menu 1 ($65) then it should multiply the $65 for menu 1 option by the QTY in the single product field e.g. {menu1:2.1}*{product:1.3}
Thanks David, what happens say for example you have a single product field (say the price is $12 (per person) then you have a 2 menu options Menu 1 and Menu 2 (using radio buttons).
If someone say purchase 4 $12 tickets and chooses Menu 1 ($65pp) how would you multiply the Menu 1 option price by the quantity (4)? would it be something along the lines of:
{Single product (Quantity):1.3}*{Menu (option ):2.1}
so that the Calculated price (sub total price) would equal $308 ($12 x 4 + $65 x 4)
You will want to add the product price with all of its options. You wrap this part of the equation in parenthesis so it will be calculated first. Then you multiply the product total (the product price and all of its options) by the quantity.
There is an example of this in the calculated form total section above. Let me know if you need any further clarification. :)
Noob question here but what is the .2 at the end reffering too? in this string? {Simple Product (Price):1.2} i assume the 1 is the ID of the field but not sure what the .2 is
Hi Wayne, good question. Some fields in GF consist of more than one input. Checkboxes for example. Each checkbox is a different input but they’re all part of the same field. So you can target specific checkbox inputs by add a decimal after the field ID and then specifying the input ID you wish to display. So if you wanted to target the third checkbox of a checkbox field and the field ID was 12, you would write 12.3
This same concept applies to single product fields as well. There are three possible inputs: product name, price and quantity. If the product field ID is 8, you can target the price input with 8.2.
Good Work.
I’m wondering how can i make conditional calculations? For example: If a quantity is more than x, use a formula…
Hi David, single product fields are not available for conditional logic; however, using a Number field configured as a calculation you can store the quantity like so: http://grab.by/e1cM
You can then apply the conditional logic to your calculated product field based on the calculated number field like so: http://grab.by/e1cS
thanks for that quick example. works!
http://www.thomas-henry.de/thomas-henrys-little-shop/
Nice! Looking good. :D