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 46+ essential add-ons for Gravity Forms with support you can count on.
Hi, I tried to implement Gravity Wiz // Gravity Forms // Calculated Shipping using https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-calculated-shipping.php
I created 3 calculated product fields. Each field have conditional logic and calculation and have right values.
So I want if subtotal value is lower than 999, use 135 as ‘field_id’ if subtotal value is between 1000 and 2500, use 137 as ‘field_id’ if subtotal value is bigger than 2501, use 135 as ‘field_id’
I just try to add ‘field_id’ => $field_id instead my static value field id (135) in snippet configuration part.
new GWCalculatedShipping( array( ‘form_id’ => 16, ‘field_id’ => $field_id, ) );
So I changed snippet code to
/** * Gravity Wiz // Gravity Forms // Calculated Shipping * https://gravitywiz.com/ * * Instruction Video: https://www.loom.com/share/aa10e3aceb4247528a27d1b27cc50516 * * A simple method for using a calculated product field as a shipping field. This provides the ability to use * calculations when determining a shipping price. * * Plugin Name: Gravity Forms – Calculated Shipping * Plugin URI: https://gravitywiz.com/ * Description: Use a calculated product field as a shipping field. * Author: Gravity Wiz * Version: 1.1 * Author URI: https://gravitywiz.com/ */ class GWCalculatedShipping {
}
add_filter( ‘gform_get_input_value_16_123’, $value, 10, 4 );
else if ($value > 1000 && $value < 2500) { $field_id=137; } else if ($value > 2501) { $field_id=137; }
Configuration
new GWCalculatedShipping( array( ‘form_id’ => 16, ‘field_id’ => $field_id, ) );
How can I achieve this code works?
Thanks
Hi Serhat,
If you’re a Gravity Perks customer, we’d be happy to give you a hand with setting this up. Drop us a line on our Support form.
You might also want to check out our Advanced Calculations perk. It adds if/elseif/else logic to calculations, which you could use in your calculated product field. That would let you achieve this without having to customize the snippet.
Hello, can I use the conditional pricing to also work out shipping costs for different postcodes?
Hello Martin, The best way to handle this is to simply use multiple Shipping fields with Gravity Forms conditional logic set to show a specific Shipping field when a certain postal code is entered in another field.
I’ve tried doing this but Gravity Forms won’t let me select a number field in conditional logic that is based on a calculation. Is this no longer possible? Thanks!
Hello Kathy, that is a bit of a strange one. I just tried this out and cannot recreate that issue. You can check and make sure another one of your plugins is not disabling this feature. What version of wordpress/gravity forms are you currently using?
Hi,
i’ve tried this on my website with the subtotal shortcode, but the number field doesn’t show the subtotal. Did I do something wrong?
Thanks in advance!
Jeroen
Hello Jeroen, We have received your support ticket and will get you an answer as soon as we can. Thank you!
There is no way that depending on a value you assign a shipping class?
Hello Jaime, Do you by chance have a use case for this one that we could possibly give you a much more in depth answer. Thanks!
When I use this, the value calculated and shown to the user on the front end is correct, but the value stored in the database Entries is not?
My setup: I have a dropdown product (MBSR Course) with 3 options, and a field (Current Exchange Rate) that I populate with a custom function.
The calculation I’m using (on a Number field) is: {Current Exchange Rate:1} * {MBSR Course:4}
For example, if the user selects a product with a value of 1000, and the current exchange rate is 0.0715, the total shown on the form is 343.2 (which is correct), but that same field stored in admin when the form is submitted, is 461000??
What am I doing wrong?
Hi Amanda, it sounds like you’re using all default Gravity Forms functionality. If you’re using the latest version of Gravity Forms and still having issues, I would reach out to Gravity Forms support.
Hey David,
I’m not getting this to happen for some reason. Here’s the link: http://florider.ca/purchase-form/
Trying to set it up so that when 1 item is sold they are charged once for shipping. If they order 2 items, I need to double the shipping amount and so on. So add 38 $$ for every item purchased.
Thanks, Doug
Hi Doug, it sounds like you want calculated shipping rather than conditional shipping. Try this snippet: https://gist.github.com/spivurno/7356056 You’ll just need to add a Calculation field to your form and set it as the “field_id” in the snippet config. It will automatically be converted to a shipping field on submission.
Great workaround… Looks like this is exactly what I need as well. Once I change the “feild_id” to be the calculation field from our form, does this new file go in my file structure at the root level, in the gravity form plugin directory or elsewhere?
Thanks in advance.
I am trying to do the same thing Kerry is doing but the nomenclature is confusing. When you say “add a calculation field” do you mean a shipping or quantity field? I am not sure which field to link to in the snippet. I have a crude dropdown now that is kind of on the honor system where they select the quantity of tattoo kits they order and that will get the correct shipping, but what you propose sounds less cumbersome.
Hello Joni, Excellent question. This would be a calculated product field so you would add a product field and enable calculations on that field. Then you would use that field for the ‘field_id’ within the snippet. Hopefully that helps out!
Hi, Ryan. I couldn’t get it to work because if I use a calculation in the product field, it won’t give the price. What I need should be a very simple thing to execute in the ecommerce world. Calculate shipping based on the number of items ordered. Why this is so difficult escapes me. I guess i will stick with my crude way of doing things for now since the client is not keen on spending a lot of money for a full bore ecommerce solution.
Im having issues with this. i have it setup so that when a customer chooses products with a total of greater than 1 or less than 500 the shipping shows up, and it works great BUT when the form is sumbitted even tho the total value is greater than 500 the shipping value that was hidden and not counted into the total now shows up in the total after submission and in the email sent.
Any ideas as to why this happens?
the form im talking about is at: http://www.peopleswellness.com/order-medlem/
Hi Micke, could you send me an export of this form?
yes, give me your email
david [at] gravitywiz [dot] com
Issue came back, this method simply doesnt work for me, and i suspect that it has something to do with currencies and the way they are calculated when the form is submitted.
I have set it up exacly like your example above and it works fine until you submit, the total changes and the shipping is added in despite the value being greater than the (in my chase 500) in the conditional logic
After a lot of troubleshooting i found out that if the calculated value is above 5000 the shipping works correctly, as if when you submit the form the 500 value turns into 5000 and checks for that instead.
Would love it if someone else had the same issue and how/if they resolved it could share the solution.
Thanks
I just tried with the simplified form you sent and it works as expected on my end. I would try doing a theme/plugin conflict next.