Subtotal Merge Tag (for Calculations)

A simple way of getting the subtotal for your Gravity Form calculations.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

November 4, 2019: Fixed notices caused by indirect modification of an overloaded element.

Stop! There's a better way.

This snippet is available as a plugin with Gravity Perks, a suite of over 46 premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

Editor’s note: Our new eCommerce Fields plugin makes this 10x easier. πŸͺ„

You’re welcome to use the snippet below, and we’re leaving this page live just in case. But you should know we’ve since released a new perk, Gravity Forms eCommerce Fields, that will easily handle all subtotal calculations out-of-the-box with no coding required.

Gravity Forms eCommerce Fields makes your forms eCommerce-friendly with support for Tax, Discounts, and Subtotal fields and includes a treasure trove of other magical eCommerce tools!

The snippet below was a great option before we released Gravity Forms eCommerce Fields. It may still be helpful to some, but it requires a bit of configuration and still does not come close to the level of functionality provided in our new perk. For example, the subtotals feature in eCommerce Fields helps your users better understand their orders in real-time, and can show the subtotal before shipping, coupons, and taxes have been applied.

Watch a quick overview:

If you still want to download the Subtotal Merge Tags (for Calculations) snippet, read on and download it below.Β 

Prior to Gravity Forms eCommerce fields, there was no easy way to get the current total (let’s call it the subtotal) of the form for use in calculations. It was possible but you would have to enter all of your product merge tags into a long and complicated formula to get the subtotal.

This snippet helps you avoid that hassle by providing a {subtotal} merge tag for use in your Gravity Form calculations.

Please note:Β The {subtotal} merge tag is only available in fields that support calculations.

How do I install this snippet?

Easy peasy. Just copy and paste the code above into your theme's functions.php file.

How do I use this functionality?

This snippet will add a new “Subtotal” merge tag to the merge tag select available for the “Formula” setting on Calculation fields. Selecting this option will insert the {subtotal} merge tag into your “Formula” setting. You can then use all available mathematical operations available to this field to manipulate this subtotal as needed.

formula-subtotal-merge-tagFormula Setting: Subtotal Merge Tag
formula-subtotal-taxFormula Setting: Subtotal Used to Calculate Tax

Comments

  1. Christopher Grasso
    Christopher Grasso November 8, 2022 at 3:05 am

    Hi David,

    I have been using this snip it for a while, it has always worked great. PayPal recently reached out and had us switch our gateway to Gravity Forms PayPal Checkout Add-On, instead of the now legacy Gravity Forms PayPal Payments Pro Add-On. For some reason, the {subtotal} merge tag now breaks the form, it won’t submit with this tag active on a product calculation field. This is the vague message I got back from PayPal support: Within the API request history, I found requests with status codes 400 and 422. 422 indicates UNPROCESSABLE_ENTITY and 400 indicates Bad Request. The 422 was due to content within the request that did not follow the required logic: “issue”: “AMOUNT_MISMATCH”, “field”: “/purchase_units/@reference_id==’default’/amount/value”, “description”: “Should equal item_total + tax_total + shipping + handling + insurance – shipping_discount – discount.”,

    Thanks for any insight you can give.

    Reply
  2. Mary Stewart
    Mary Stewart January 19, 2022 at 12:00 pm

    I am using the form to collect total entries of Random Acts of Kindness when someone enters the total “number” of total acts of kindness it charts it on the Ultimeter thermometer as total numbers of entries, not the actual number . Example, If someone is reporting 10 acts of kindness performed for a group, the Ultimeter only sees it as 1 but I need it to see it as the number entered, in this case, 10. Can you help ? https://localkindness.org

    Reply
  3. jlvz
    jlvz November 10, 2021 at 2:05 am

    Hi,

    i’ve this issue : Notice: Indirect modification of overloaded element of GF_Field_Checkbox has no effect in E:\Dropbox\SITES\test\www\wp-content\themes\test\inc\gw-calc-subtotal.php on line 123

    Do you have an idea ?

    Thank

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff November 10, 2021 at 3:13 am

      Hi jlvz,

      We’ll have to dig into this on your website, to determine why it isn’t working. If you have an active Gravity Perks License, you can get in touch with us via our support form so we can assist you. That said, you may want to use our GP Ecommerce Fields Perk, which is more user-friendly and up to date.

      Best,

  4. Robby
    Robby May 27, 2020 at 8:21 am

    Thanks for this,

    i used a multisite form with different products + options and amounts and need the following calculation :

    Form page 01 with Product #1: Internet Flatrate (yes/no) + 25$ per month if yes –> show field Β»Private IP4 Adress (yes/no)Β« + 5$ per month if yes –> show field Β»AmountΒ« (1-10) Subtotal = Price per Month (product01 + (option*amount))

    Form page 02 with Product #2: Voice-over-IP (yes/no) + 15$ per month} if yes –> show field Β»Additional phone numbers (yes/no)Β« + 5$ per month} if yes –> show field Β»AmountΒ« (1-10)} Subtotal = Price per Month (product 01 + (product 02 + (option*amount)))

    Here is a small example: Internet Flat 25$ + 3xIP4(5$ per IP) – 40$ per month

    • VoIP 15$ + 6*additional number(5$ per number) = 45 $ per month

    Total: 95$ per month

    Any ideas how I can achieve this?

    Thanks for your help.

    Reply
  5. Alissa Eggleston
    Alissa Eggleston May 22, 2020 at 7:51 am

    Thank you for this! It’s really helped.

    I get a strange error though when I view an entry . Cannot modify header information – headers already sent by (output started at /home/****/public_html/****/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code:222) in /home/*****/public_html/*****/wp-admin/admin-header.php on line 9

    It’s coming from this portion: function add_merge_tags( $form ) {

        $label = __('Subtotal', 'gravityforms');
    
        ?>
    

    <

    script>

    it only shows when I view an entry. I’ve checked for extra lines and deleted the space after the ?> but it’s still there.

    It’s not affecting the site at all – just wondering if I should be looking into it further?

    Reply
    1. Ryan Donovan
      Ryan Donovan May 20, 2020 at 2:43 pm

      Hello Anthony, This snippet would allow for the Subtotal Merge tag to be displayed and used within calculations. So you could set up a calculation field that uses the subtotal and calculates how much the tax should be that can later be used within the total, you can then name this tax to display how much they are being charged. Our Gravity Forms eCommerce Fields plugin already has a tax field pre-built within it to make it easier for you.

  6. Sarah
    Sarah April 17, 2020 at 11:20 am

    Thank you so much! This is epic for long forms. I wasn’t able to exclude tax from a “tip” field, but that’s okay! If anyone has a hint for me there, it’s appreciated. Thanks again for this solution!

    Reply
    1. Sarah
      Sarah April 17, 2020 at 1:41 pm

      Hi and thanks! A product field called “tax” (quantity field disabled) with the calculation: {subtotal} * .082

      Here’s the working form in case it helps anyone else, too. It’s as simple as can be, for a temporary solution. They are a local food truck trying to keep some business going during the pandemic. foodlishus.com/order/

  7. Suusa
    Suusa April 13, 2020 at 9:24 am

    Hello!

    When I edit the single form entry in the admin side all the fields where the subtotal is used turn into zero values. Seems to be a bug or am I missing something here?

    Thanks!

    Reply
    1. Ryan Donovan
      Ryan Donovan April 13, 2020 at 10:03 am

      Hello Suusa, how are you currently using the subtotal field? Is it calculating numbers, products or what? Do you have a public site where we can see this information? Thank you so much!

    2. Ryan Donovan
      Ryan Donovan April 13, 2020 at 1:07 pm

      Hello Suusa, I have just tested this out and everything seems to be working correctly. Are you using products to calculate the subtotal? When used with products the subtotal should calculate. Could you give that a try? πŸ˜€

  8. Michael
    Michael February 25, 2020 at 12:28 am

    Thanks for this,

    trying to achieve the following:

    Calculation: {subtotal} *0.15. (Add tax to product price). – WORKS PERFECT

    Calculation 2: {subtotal} *0.025 (Add credit card fee). – HAVING PROBLEMS

    TOTAL PRICE:

    Problem is ‘calculation 2’ changes the subtotal which then makes it incorrect for calculation 1.

    Any ideas how I can achieve this?

    Thanks for your help.

    Reply
    1. Ryan Donovan
      Ryan Donovan February 25, 2020 at 10:20 am

      Hey Michael, Looks like you are running into an issue with using two subtotal merge tags. Currently what is happening is the first calculation is running then replacing the subtotal with the new calculated subtotal. When you get to the next calculation it will now use the new subtotal in this calculation. You can accomplish this the easy way by getting Gravity Forms eCommerce Fields or you could actually reserve a subtotal field with just the {subtotal} merge tag, then use that fields price to create a new field with calculations that uses the new subtotal fields price merge tag ({Subtotal (Price):3.2}) to calculate the tax and fee. If you are still having issues after using the modifier this way, could you please drop us a support request. :)

  9. Dave
    Dave January 27, 2020 at 12:24 pm

    I’m not having much luck getting this to work. I have a multi-page form with products on a few pages but the total for my calculation field is zero.

    Reply
    1. dave
      dave January 27, 2020 at 12:40 pm

      never mind. It was a formula error. Thanks for always being so awesome. Love you’re site and your code snippets.

    2. Ryan Donovan
      Ryan Donovan February 14, 2020 at 12:10 pm

      Hello Dave,

      Happy that you were able to get the calculation on your total form to work. Have a great day! :)

  10. shikha choudhary
    shikha choudhary January 23, 2020 at 2:55 am

    Can I able to use IF ELSE condition in merge tag calculation .please help me how we can do this. I am doing like below but it is not working for me. if($ 1-Year:90:48.88) 58.56 else 4.88

    Reply
    1. Scott Ryer
      Scott Ryer Staff February 17, 2020 at 2:59 pm

      Gravity Forms doesn’t support if/else conditions in merge tags, but it does support conditional logic for number field. You could add conditional logic to a Product field and show/hide it based on the results of a calculation in a hidden number field.

  11. Robert Chow
    Robert Chow October 21, 2019 at 2:40 am

    Recently I noticed this error after either WP or GF got updated. If the disable the plugin, the error goes away. I’m using version 1.2 of the code.

    Notice: Indirect modification of overloaded element of GF_Field_Checkbox has no effect in /public_html/wp-content/plugins/gw-calc-subtotal/gw-calc-subtotal.php on line 123

    [redacted for brevity]

    Reply
  12. Laritza
    Laritza June 24, 2019 at 3:21 pm

    I need help! I have a form for which I have to duplicate the value of the first product is AM and PM are checked, then there is another option to select an additional product from a dropdown but this one is NOT duplicated even if AM and PM are checked. Is there any way I can do this? If I can do that then I could also add the subtotal paypal fee calculated field. I read the snippet and there is an option to not include a field in the subtotal calculation but I have another form using the subtotal field so that would not use the field number in the calculation and brake the other form. Thanks! Here is the form: http://yorkshireterrierclubofthenationscapital.org/index.php/specialty-shows-2019/

    Reply
  13. Troubleshooting Issues with Calculation Results - Gravity Forms Documentation June 5, 2019 at 2:29 pm

    […] total field not being available is to use a Number field with a subtotal calculation. Refer to the GravityWiz Subtotal Merge Tag (for Calculations) article for more […]

    Reply
  14. Conrad
    Conrad May 1, 2019 at 2:21 pm

    I’m using Stripe as my payment processor for Gravity Forms. I need to add tax to my form, but my current setup just sends the total amount to Stripe, and I would have to figure out how much was tax separately. How does tax show up in Stripe through the ecommerce perk? Will it show up in Stripe’s tax field, or will it just show up as the total transaction amount?

    Reply
    1. David Smith
      David Smith Staff May 2, 2019 at 9:16 am

      Support for mapping the Tax field to Stripe’s tax field is on our roadmap but not currently supported. For now, the Tax field is included in the cumulative total sent to Stripe.

  15. Jon Eynon
    Jon Eynon May 1, 2019 at 12:42 pm

    Does this subtotal save with the form? I am having issues with running some gv_math because I am trying to access the Totals from a form but it tells me that Totals are allowed in gv_math. I am wondering if this saves as a number or something that I can access later? My Total field is literally summing up 100s of items so to make a calculated # field is not possible given the form. Any thoughts?

    Reply
    1. David Smith
      David Smith Staff May 1, 2019 at 1:06 pm

      The {subtotal} merge tag does not impact how the field data is saved. What you see on submission should be what is saved in that field. I haven’t used gv_match but I would not expect this functionality to impact whether or not that functionality works.

    2. Jon
      Jon May 1, 2019 at 2:00 pm

      But are you saying that subtotal is saved with the form? Or is it just doing its thing on the live form and then doesn’t go anywhere once submitted? Gravity View Math doesn’t let us do math on the Total form field in Gravity Views so I am trying to come up with a way to get my Total over without it being incompatible. I was hoping this might be it. Does it save as a number in the database?

    3. David Smith
      David Smith Staff May 2, 2019 at 9:18 am

      The value of the field is saved with the entry including whatever the calculated value of the {subtotal} merge tag. Including the {subtotal} merge tag in a calculation-enabled field does not impact how the calculation-enabled field works. If you Gravity View typically works with calculation-enabled fields, it should work with the calculation-enabled field that contains the {subtotal} merge tag.

  16. Sean Ramsey
    Sean Ramsey March 29, 2019 at 3:15 pm

    Please help. I have a dev environment and am getting this error msg:

    Warning: Invalid argument supplied for foreach() in /srv/bindings/38c825ddfc6b4c72b486890a3c77ee96/code/wp-content/plugins/gravity-forms-add-subtotal-merge-tag-master/gf_subtotal.php on line 234

    This is not showing up in the Production environment.

    Reply
  17. Aaron Rudd
    Aaron Rudd February 8, 2019 at 4:29 pm

    I’m using this snippet for a donation form for my client.

    When any decimal appears after the dollar amount $10.(50cents), the Credit Card fields throws an error:

    This value must match the regex pattern. (/\A[a-zA-Z0-9_\-]+\z/ does not match for the value monthlyrecurring_40_1month_10.5).

    Any helpful ideas would be appreciated.

    Thank you!

    Reply
    1. Aaron Rudd
      Aaron Rudd February 9, 2019 at 9:50 am

      My apologies. I needed to upgrade Stripe Add-On from 2.5 to 2.5.4. That fixed my issue. Thank you for responding.

  18. Layla B
    Layla B January 16, 2019 at 3:00 pm

    I need some help installing this snippet with a skilled developer, can anyone help us update our gravity form with tax calculation subtotal issue as mentioned above? I can pay you of course for the help. Currently our form is not collecting tax and it’s a problem.

    Reply
  19. Chris
    Chris December 12, 2018 at 5:07 pm

    Sorry to bug you again. I updated to WordPress 5.0 and gravity forms 2.4.3. somehow now when i am using the subtotal merge tag, all the calculations are drastically off in the negative. I have 3 products, all with a price of 0, then an option field with checkboxes for each product, containing multiple selections with prices. On my tax calculation field (.0875*{subtotal}), if I select say a product that is $75 and a product that is $85, I get a calculation of -$85,414.00. if I change the calculation formula to only be {subtotal} and nothing else, the $75 and $85 product tally to Price: -$745,915.00. Could something have changed in the way this merge tag is tallying the subtotal? Thanks David!

    Reply
    1. Jeff
      Jeff December 17, 2018 at 9:47 am

      I am experiencing the same issue. I had to roll back to WordPress 5.0 and Gravity Forms 2.4.2. I experience the issue with WordPress 5.0.1 and Gravity Forms 2.4.2 and the problem seems to worsen with 2.4.3.

  20. Scott Carter
    Scott Carter December 10, 2018 at 3:15 pm

    The newest version work with Gravity Forms 2.4.1 but breaks after updating to WordPress 5 with the following notice:

    The plugin gravity-forms-add-subtotal-merge-tag-master/gf_subtotal.php has been deactivated due to an error: The plugin does not have a valid header.

    Any thoughts on how to resolve this?

    Reply
  21. Christopher Grasso
    Christopher Grasso November 30, 2018 at 11:07 am

    Hi David, Im hoping you can help me out with this.

    i’ve began seeing a warning on all pages where i have a form, when this snippet is in my functions file: Warning: Invalid argument supplied for foreach() in /home/redacted/functions.php on line 597

    597 appears to be at the end of the snippet, located in the // check if form is passed section:

    foreach( $form[‘fields’] as $field ) {

    I updated gravity forms to 2.4 at some point this past week. I haven’t made any other changes to the functions file or gravity forms. The snippet was working fine for the past few months.

    Thanks Chris

    Reply
    1. Lynne Arnold
      Lynne Arnold November 30, 2018 at 3:11 pm

      It appears that this doesn’t work anymore with the latest version of Gravity Forms, 2.4.1. If there is a fix, I would love to know. Thanks, Lynne

    2. Steve Wolfson
      Steve Wolfson November 30, 2018 at 6:54 pm

      Hi, I’m having the same issue that Christopher Grasso reports. With Gravity 3.4.1 installed the Subtotals routine generates multiple error messages Warning: Invalid argument supplied for foreach() in /home/{redacted …}/functions.php referencing the line foreach( $form[β€˜fields’] as $field ) {

      I’ve restored the site to Gravity 3.3.6 and the form works correctly again. Thank you for assisting!

  22. Frank Gomez
    Frank Gomez November 29, 2018 at 9:24 am

    Hi David, I want to be sure that a “SubTotal” field is “accessible” by the Stripe Addon in the Feed settings

    I want to create a subscription Subtotal and a Setup Fee subtotal and use the STripe Addon to create a feed that uses those subtotals Currently. The way I see it the Stripe Feed only accepts Product Fields or the Total. I want to be sure that the subtotal fields also work with the Stripe Feed.

    Reply
    1. David Smith
      David Smith Staff November 29, 2018 at 9:55 am

      This snippet does not provide a Subtotal field, Frank. Are you referring to the GP eCommerce Fields plugin? If so, no, the Subtotal field is not available to Stripe. This is something we’d like to add support for in the future.

    1. Edward Claughton
      Edward Claughton December 1, 2018 at 3:19 pm

      Hello,

      The sub-total is actually not quite fully working correctly. When I select the “products”I want to calculate in the sub-total, it calculates everything, not just what I selected. Note, the way I have the products structured is some of them had the same name although different product fields with different GF product numbers. I thought that might be causing it so I adjusted the names of the ones I want to include in the sub-total and still having the same issue. Could it be the names in the database are still the same or is this a bug?

      Thanks.

  23. James
    James July 17, 2018 at 8:24 am

    Thanks for this. I used this solution to allow me to use the subtotal in a conditional statement for another field. Very helpful.

    Reply
  24. Arten
    Arten July 8, 2018 at 7:08 pm

    In general, I have a form http://35.226.46.43/create-shipment/, I need to pass it a little bit. make the connection between the areas allow delivery from MANHATTAN to MANHATTAN – $ 75 etc. And change the price calculation depending on the weight if more than 20 lb then + 0.75 $ per lb How can i do it? Thx

    Reply
  25. Ronny
    Ronny June 28, 2018 at 1:20 pm

    I’m interested in passing the WooCommerce cart total into a Gravity Form via merge tag so that I can apply additional calculations based on user selections. Specifically, I’m trying to create a lease calculator that converts the cart total into a monthly lease price based on user selecting a lease type and lease terms. Based on the user selections, a lease rate would be multiplied by the cart total in order to calculate the monthly lease. Can this be done using Gravity Wiz?

    Reply
  26. Janice
    Janice June 10, 2018 at 11:02 am

    Having a hard time showing taxes ony form, used the subtotal as mentioned above but it totals to a crazy large number. Unsure what I’m doing wrong. Help!

    Reply
  27. Mike
    Mike June 4, 2018 at 8:36 am

    I’m using this code to calculate a discount. It works perfectly (subtotal * number of checkboxes checked * discount percentage)

    The issue is that this “discount” is being added to the total, not subtracted from it. From what I can tell, there’s no way to subtract the total from the actual total, is there?

    Reply
    1. David Smith
      David Smith Staff June 4, 2018 at 11:14 am

      You’ll need to add the discount as a negative amount in a Product field. That is the only way GF will pick up on it.

    2. Mike
      Mike June 4, 2018 at 11:17 am

      How can I do that? The discount is a calculation, so I can’t add it as a negative amount.

      Or I can’t figure out how, anyway.

    3. Mike
      Mike June 5, 2018 at 8:13 am

      That doesn’t seem to work.

      My calculation [(({subtotal}.05){Number:29})-({subtotal}*.05)] works perfectly to calculate the discount. (FYI, it’s 5% discount per add-on they check, which I’m pulling from the Number:29 field, which is a sum total of checkboxes checked, minus one discount for the initial add-on)

      If I add a – in front of the formula, the math somehow becomes wrong.

      No minus sign and the discount adds up to $256.25 (which is right; 25% of the total of all 6 add-ons – 5% per add-on after the 1st one)

      If I add a minus sign, it adds up to -$358.75, which is wrong.

      Same exact formula, but adding the – in front of it somehow breaks the equation.

    4. Mike
      Mike June 5, 2018 at 8:14 am

      Aha!

      I added another set of parenthesis around the whole thing and now it’s calculating properly!

  28. Stefani
    Stefani November 27, 2017 at 4:30 pm

    Hi there! Thank you so much for this snippet! I placed in the php file and see the {subtotal} merge tag. But, it doesn’t seem to be working. I have a box for donors to check if they want to include the merchant fee for PayPal. If they check the box, the Product field comes up called Merchant Fee, and in that field, I have a calculation. I’ve tried (({subtotal}*2.2/100) +0.30), ( {subtotal} * 0.022 ) + 0.30) and even just {subtotal} * 0.022, but no matter what I use, nothing is showing in the Merchant Fee field. Here is the URL – the form is in the blue bar (sorry about the music auto-playing): https://gbgrr.org/tree-of-hope/

    I’d appreciate ANY extra sets of eyes! Thank you!

    Reply
    1. David Smith
      David Smith Staff November 29, 2017 at 7:58 am

      Hi Stefani, the demo for this snippet appears to be working still. If you’re still having issues, I would recommend checking out Gravity Forms eCommerce Fields which provides this same functionality (and much more) as a plugin; no code required.

  29. Building A WordPress Donation Form Using Gravity Forms, MailChimp and Stripe &#8211; INN Labs November 16, 2017 at 10:57 am

    […] Forms Add Subtotal Merge Tag (This is an INN fork of Subtotal Merge TagΒ and must be installed […]

    Reply
  30. Gravity Forms Pricing: Adding Tax &#8211; Gravity Forms Documentation October 5, 2017 at 3:35 pm

    […] Subtotal Merge Tag (for Calculations) via GravityWiz.com […]

    Reply
  31. hannansoft
    hannansoft July 5, 2017 at 8:06 pm

    Hi it is a good snippets but when i use subtotal tag , my form doesnt perform well on mobile phones. how can i fix it? thanks

    Reply
  32. Chris
    Chris March 24, 2017 at 8:29 am

    Hello David! Does anyone commented that this tag doesn’t work on the email notifications or Gravity PDF templates?

    When I use the {subtotal} tag, it outputs nothing on the HTML template for the email or PDF :-(

    Reply
  33. Building A WordPress Donation Form Using Gravity Forms, MailChimp and Stripe | INN News Nerds February 14, 2017 at 1:51 pm

    […] Forms Add Subtotal Merge Tag (This is an INN fork of Subtotal Merge TagΒ and must be installed […]

    Reply
  34. Maggie Cameron
    Maggie Cameron February 6, 2017 at 12:30 pm

    Hello, I’ve been using this very successfully for quite a while now, and it’s still seems to be working. However, when I view my form entry, I now get this message:

    Header information – headers already sent by (output started at /home/girlcook/public_html/wp-content/themes/parallax-pro/functions.php:446) in /home/girlcook/public_html/wp-includes/option.php on line 828

    and

    Header information – headers already sent by (output started at /home/girlcook/public_html/wp-content/themes/parallax-pro/functions.php:446) in /home/girlcook/public_html/wp-includes/option.php on line 829

    Line 446 is of course part of the Subtotal Merge Total code. Any ideas what’s happening?

    Reply
  35. Daniel Helen
    Daniel Helen February 1, 2017 at 9:23 am

    I have a form which offers multiple payment options, with a setup similar to the one described here: https://gravityplus.pro/how-to/setup-multiple-payment-options-on-one-gravity-form/

    For the transaction fees, each payment type has its own product field with a calculation – using the subtotal tag – that shows/hides according to some conditional logic rules.

    While the seems to work fine in Chrome (though it is a little slow when I try to select items from drop-downs), the JavaScript crashes completely in Firefox.

    You can recreate the issue here: https://www.tolkiensociety.org/events/seminar-2017/book/beta/

    This is error message:

    http://snippi.com/s/1vz74bm

    Reply
    1. David Smith
      David Smith Staff February 1, 2017 at 11:33 am

      Hi Daniel, the {subtotal} merge tag does not perform well when used multiple times on the same form. If you’re attempting to add any fee, we recommend using a Tax field instead (via the GP Subtotal & Tax perk; available by request to Gravity Perks license-holders).

    2. Daniel Helen
      Daniel Helen February 1, 2017 at 11:41 am

      Hi David, thanks for you reply. Is there no workaround given that only one field using the {subtotal} tag is visible at any one time?

    3. David Smith
      David Smith Staff February 1, 2017 at 11:46 am

      I’m sure there is but it would require customizing the snippet to handle it. While the snippet is still free and publicly available, I’ve invested in a much better solution with GP Subtotal & Tax. :)

  36. Chris
    Chris January 30, 2017 at 12:53 pm

    Hi David,

    I have GP installed and am trying to perform a calculations which I need your help with please. I have a number of products in Group A which I want to apply discounts/loadings to and get a total. I then have another Group B which I perform separate discounts or loadings to to create another total which I add to the first and then add tax

    All the products are on the same page. The subtotal snippet seemed like a solution but I can’t seem to create 2 separate sub totals and then add them together

    Any ideas greatly appreciated! Thanks in advance

    Reply
    1. David Smith
      David Smith Staff January 30, 2017 at 1:57 pm

      Hi Chris, if you’re a Gravity Perks user, get priority support here: https://gravitywiz.com/support/ We have a new perk coming out very soon which we’d love for you to take for a spin. I think it’ll be a great fit for what you’re trying to do here.

  37. Mische
    Mische January 26, 2017 at 2:53 pm

    I figured out the issue – for some reason the fact that the Subtotal in form #1 is a Price Field makes it angry. As soon as I change the Subtotal field in form #1 to a number field, all of the experimental, dynamically populated, data-hungry fields I’ve built in form #2 come alive with form #1’s subtotal.

    So my grand plan for anyone else trying to come up with a discount solution not using Coupons: (yet to be tested but still a plan) 1. Gather subtotal from form #1 2. In form #2, bring the Subtotal in but as a Product Field this time. 3. Add a User Defined Product Field (that only the Admin can edit) so the Admin can enter whatever total dollar amount they want to discount. 4. Add the code from example #1 on the GravityHelp forum. To remove negative product issue. https://www.gravityhelp.com/documentation/article/gform_paypal_query/

    Hopefully that’ll work out. For my situaion, simply using the code in #4 in the main form won’t work. My client actually waives the lower of 2 fees – when those fees are waived and how much is waived are both conditions that are all over the place so I’d have to create about a thousand coupons and my client’s team would have to keep track of them… no good. So I thought, what if the Subtotal becomes my highest priced product? Since I don’t need form #1 to actually go to Paypal based on my client’s workflow, there’s no reason the Subtotal can’t be a Product (and the highest priced one) on another form.

    David, thank you again. You rock. Honestly.

    Reply
  38. Marko Sustic
    Marko Sustic January 26, 2017 at 5:51 am

    Hello David,

    First of all thanks for the awesome snippet. It saved me multiple times and im using it without problems for a long time now.

    Recently i noised in my cPanel that my errorLog was edited and when i looked in to it i saw that it errors out on 36th line of code of this snippet. I will provide the exact line in the code area.

    the error is something like “invalid argument supplied at line …” and the line is in the code below.

    so foreach gets wrong arguments.

    Is this a common problem? How do i and do i have to fix it?

    I will add that the snippet work without problems. It just puts this error messages in my log file every day a few times.

    Thanks in advance

    I have new version od wordpress installed and new version of gravity forms

    Marko Sustic

    Reply
    1. David Smith
      David Smith Staff January 27, 2017 at 9:21 pm

      Typically this occurs when Gravity Forms attempts to load a form that does not exist. Most often a user error when an incorrect form ID was specified for a shortcode. If you’re able to recreate the error consistently with a valid form, let me know.

  39. Mische
    Mische January 22, 2017 at 4:34 pm

    Hi David. Thanks for another fantastic & helpful tool.

    Can you see a way to use the subtotal field to act as a step to subtrack from the total before submitting to PayPal? I know that question is not specific at all – I basically need exactly what his person did (https://www.gravityhelp.com/forums/topic/remove-validation-for-negative-price ) but don’t have the chops to pull off the hook you mentioned, so I’m trying to find a work-around that avoids the negative price error from Paypal. (my client has too many possible pricing & fee reduction scenarios just like that guy’s situation)

    I’m having an oddly tough time with such a simple concept. It would be amazing to have: [subtotal] [field for subtracted amount that the client can use] [reason for reduction so it’s on record, again to be filled in by client abt their customer] [total that’s sent to Paypal]

    It would look like: Subtotal $4700.00 – $1200.00 [Shoreline Stabilization fee waived – Application includes New Structure as well] Total: $3500

    Fingers crossed that you can help!

    Mische

    Reply
    1. David Smith
      David Smith Staff January 23, 2017 at 7:54 am

      Hi Mische, we do not currently have a solution for this one. Leaving this open for any other users who might have a suggestion.

    2. Mische
      Mische January 24, 2017 at 2:54 pm

      Hmm. I’m trying to get crafty with this and I may have a solution. But first, can you help me get the Subtotal from form #1 to form #2? If this thing I’m trying to do works, I swear I’ll share my solution in great detail.

      Here’s the skinny: In form #1, my {subtotal} is calculating in a Product field. In form #2, I’m trying to dynamically populate another product field with form #1’s subtotal. To do this I tried adding a parameter name to the field in each form, then went to the confirmations and tried to pass it as a query string. (it doesn’t have to be a product field in form #1 – it could be a number field just as well. But in form #2 it does have to be a product)

      I’m definitely missing somthing critical.

    3. David Smith
      David Smith Staff January 24, 2017 at 5:55 pm

      If you’re passing the value of Field A from Form 1 in the query string with a query string parameter of “&fielda={Field A:9}” (pretending that 9 is your field ID), and on the Field B on Form 2 you have the dynamic population parameter set as “fielda”, the value from the query string should be populated into that value.

  40. Mi
    Mi January 9, 2017 at 9:10 am

    Awesome plugin btw.

    I have question about integrating paypal checkout with the subtotal. The paypal extension we are using only takes payment amount from the pricing fields. I was able to use product field with your extension’s calculator but after clicking submit, the page would not redirect to the paypal check out page.

    When I select payment amount on other product field and total field, it works. Please advise.

    Thanks in advance!

    Reply
    1. David Smith
      David Smith Staff January 10, 2017 at 8:42 am

      Hi Mi, I’ve tested this with the official Gravity Forms Paypal add-on and it works as expected. What add-on are you using?

    2. Min
      Min January 10, 2017 at 10:13 am

      We are using Gravity Forms PayPal Standard Add-On. The plugin is update but still unable to redirect to paypal checkout page.

  41. Andrew
    Andrew January 5, 2017 at 5:34 pm

    Hi David,

    if I wanted two fields one to add a ‘processing fee’ of 2% of the product price and then a field to add 20% VAT but not include the processing fee would I need to get the Gravity Perks licence to enable me to do that easily?

    Reply
    1. David Smith
      David Smith Staff January 5, 2017 at 9:44 pm

      Hi Andrew, the snippet version does not support having multiple product-based {subtotal} merge tags. It creates an infinite loop. The plugin version includes a Tax field which is more performant and provides the ability to exclude specific products from the calculated total.

  42. Eddie
    Eddie December 21, 2016 at 10:26 am

    thanks for the snipped, but for some reason as soon as i add it to my themes function file, the site breaks :( i see this message on the log file

    PHP Parse error: syntax error, unexpected ‘<‘ /themes/Minimal-child/functions.php on line 17 [21-Dec-2016 15:00:20 UTC] PHP Parse error: syntax error, unexpected ‘<‘ in /themes/Minimal-child/functions.php on line 17

    Reply
    1. Eddie
      Eddie December 21, 2016 at 11:57 am

      That did the trick! thank you! it was the PHP opening tag that was messing it up…one i removed that it worked like a charm!

  43. Todd Dengler
    Todd Dengler December 18, 2016 at 5:26 pm

    Hey guys Great post, however, I can’t seem to get this to work with the Coupon Add-on. When I add the 7% tax to the Tax field, the tax after discount still calculates for the full price, not the reduced price after the coupon. What am I doing wrong?

    Reply
  44. Lynne Arnold
    Lynne Arnold December 9, 2016 at 9:16 pm

    I got the same error that the subtotal gave a really weird amount – it was almost twice as much but not quite, so I don’t know how it calculated it. So I just changed the calculation to just show the fee itself. So mine is not entitled “Sub-total” but just “Fee.” Then the GF total is correct.

    Thank you for this REALLY helpful solution!

    Reply
  45. Lev
    Lev November 15, 2016 at 11:30 am

    Hi It is very strange that after implementing subtotal TOTAL field now showing double amounts what do I did wrong I have a promo code that activates 10% discount So here are the fields Cost– $ 80.00 10% discount -$ 8.00 Subtotal should show $78.00 So is the total should show $78.00 it shows $156.00 ( double) So where do I go wrong.

    Reply
  46. Simon
    Simon November 10, 2016 at 4:26 am

    Do you have a solution for VAT (UK 20%) when a coupon is used?

    I have a situation where I have created a subtotal the traditional way using the long list of product prices and then *0.2 but this does not subtract the value of the coupon which for arguments sake is $25. So the actual tax total is not the sum of the products minus the coupon *0.2 which for VAT purposes it is supposed to be.

    Reply
  47. Daniel GonzΓ‘lez
    Daniel GonzΓ‘lez September 21, 2016 at 12:00 pm

    Hi, i have a issue: when i used {subtotal} in number field, the form doesn’t work fine (freeze in chrome, with a script error message in firefox and in safari doesn’t work). I installed the snippet as the instructions say. And another question is, when i used the {subtotal} in a number field and i put the total field too, the number field show the same value than total field. Maybe is a clue for my issue. Thanks

    Reply
    1. David Smith
      David Smith Staff September 22, 2016 at 10:33 am

      Sorry to hear it, Daniel. If you’d like to give GP Subtotal & Tax a try, it is a perk-in-beta available to any Gravity Perks license holder. It has support for the {subtotal} merge tag as well as a Tax field that makes calculating taxes a lot easier. Just pick up a copy of Gravity Perks (if you haven’t already) and drop us a line via support.

  48. Adeline
    Adeline July 21, 2016 at 6:40 am

    Hi, I tried your code to add a discount on the total. It works well online ! Thanks ! But on the notification, the amount of the product where I put the ‘subtotal’ merge tag, displays 0€, and so, the total isn’t affected. Have you got a solution for me ?

    Thanks

    Reply
    1. David Smith
      David Smith Staff August 8, 2016 at 2:40 pm

      Hi Adeline, I just tested and this is working for me. The calculated product which includes the {subtotal} merge tag is included in the notification. If you’re still having issues, I would recommend picking up a copy of Gravity Perks and dropping us a line via the support form so we can send you a beta of the GP Subtotal & Tax perk.

  49. meir
    meir May 26, 2016 at 5:48 pm

    i am having problems: in the front end – field calculted by butotal look fine – but in the notifications, it changes and show wrong calculations…. what can i do?

    Reply
    1. David Smith
      David Smith Staff June 20, 2016 at 10:21 pm

      Hm, we’re not able to recreate this issue. Feel free to send us an export of your form.

  50. Derrick
    Derrick April 4, 2016 at 9:46 pm

    So does this replace the total then? How do you tied this in with the regular total field?

    I’m using the woocommerce addon so will this affect woocommerce checkout?

    Also, i’m getting this subtotal format. Any way to fix this – 114.99999999999999

    We only want two decimal places like this – 114.99

    Thanks

    Reply
    1. Derrick
      Derrick April 4, 2016 at 10:06 pm

      Actually what we need is different qty pricing based on product options selected. this determines qty.

      do we need the conditional pricing addon? Will this allow us to set different quantities and pricing based on product option selections?

      Thanks

    2. David Smith
      David Smith Staff April 5, 2016 at 10:22 am

      Hi Derrick,

      Almost. GP Conditional Pricing will allow you to set quantity-based pricing as well as set prices based on options selected in other fields. It only allows you to set prices for Product fields currently and not Option fields.

    3. Derrick
      Derrick April 5, 2016 at 11:38 am

      The subtotal formula works areat, but we need to pass this on to the main total. Which I cannot see how to do this. For ex, one of our products has 4 different quantities depending on options selected. Options are diameter, microns, length, etc.. The subtotal worked great. We just applied conditional logic depending on options selected and multplied by qty. Can subtotal be combined with conditional pricing and pass price onto main total? In addition, we are using woocommerce add on as well. Thanks

    4. David Smith
      David Smith Staff April 5, 2016 at 11:43 am

      You can apply the {subtotal} to the form total by included it in a Calculated Product field rather than a Number field.

    5. Derrick
      Derrick April 5, 2016 at 11:58 am

      I don’t think this will work for us. I think we have exposed a weakness in gf with the complexity of our form. We have several products and within each , dynamic pricing and qtys. I don’t fully understand your last reply.

    6. David Smith
      David Smith Staff April 5, 2016 at 12:09 pm

      Product fields can have different types. One of those types is Calculation. This will allow you to create a formula and use the {subtotal} merge tag. The total of this field will then apply to the form total.

    7. Derrick
      Derrick April 5, 2016 at 1:11 pm

      Upon further thoight on your last reply, you are saying map the total to a product field within each section with subtotal calculation within said product field? My thinking is that we can only map the total field to one product field, and we would need several product fields with different qty. We could use conditional logic to show the appropriate product field w calculation, but no way to map the main total with the appropriate product field. IS there anyway you could help us with this issue? It doesn’t seem hard, and actually something thst should be standard. I think our situation could help w development of your product.

    8. David Smith
      David Smith Staff April 5, 2016 at 2:43 pm

      Gravity Forms does not have a limit on how many Product fields can be added to the form. All Product (and Option and Shipping fields) will be added to the form total.

    9. Derrick
      Derrick April 5, 2016 at 2:44 pm

      I tried you suggestion, and fyi, you cannot apply {subtotal} in that manner.

      I included a conditional calculated product field in my section. The calculation was {subtotal}*12 and was set to display only under certain conditions. The correct amount showed in the product field we added with the calculation in the section, but the total field not reflect that amount. I am relatively new to gf, but i can say without a doubt this is a major weakness of gf, and have informed their team of such. Gf has a way to go in my opinion and is basic in regards to pricing, etc.. Question: can the price in our product field with calculation replace the total field? And can it be used with woocommerce addon? This seems to be the only way we can use calculations for our purpose is with this product field w/ calculation. Thanks

    10. Derrick
      Derrick April 5, 2016 at 2:49 pm

      I just read your last comment. We must have been commenting at the same time.

      I will have to disagree and i can prove it.

      Here is our form on our dev site – http://www.chemtrex.webcoreinteractive.com/custom-quote-form/

      Make the following selections: product – melt blown media – any diameter – 4.5 grade – standard micron – 1 length – 9.75 core – any

      As you can clearly see, the product field appears with correct total, but total field DOES NOT reflect correct total.

      So gf clearly does not support this scenario.

      Is there another workaround that you know of, or can we use the product field only with calculation as our total field?

      Thanks

    11. Derrick
      Derrick April 5, 2016 at 2:56 pm

      ok we made a modification.

      however there is still an error, and it may be in your snippet.

      Making the choices i outlined in my previous comment, you can see the product calcualtion field calculates times 12, which is correct. HOWEVER, the total field shows x 13!! An obvious error. So we will have to subtract 1 from our qty calculations. Can you maybe release a quick fix for your snippet? Thanks in advance!

  51. Min
    Min April 4, 2016 at 12:37 pm

    Hi David,

    Thanks for the awesome function. This is what I am looking for. But is it possible to use the tag, {subtotal} to output the total on Section break field or HTML field? I see that it works on the number field. I would like to display a message like: “Your total is {subtotal}! Fill the the information below to complete your payment…” on the last page of the form.

    Thanks in advance!

    Reply
    1. David Smith
      David Smith Staff April 4, 2016 at 2:23 pm

      Hi Min, it is not currently possible. You could write a bit of jQuery that would copy the value of a field to a specific element on the page though. Something like this:

      jQuery( '#input_123_1' ).change() { jQuery( '#my-custom-elem' ).html( $( this ).val() ); }

    2. Min
      Min April 5, 2016 at 11:44 am

      David,

      Thanks for the quick response. I tried using the jQuery snippet above. The subtotal is not showing on the span tag. I wonder if you can help me with it:

      jQuery( '#input_1_17' ).change() { jQuery( '#subtotal' ).html( $( this ).val() ); }

      input_1_17 is the product name field

      I also tried:

      $('#input_1_17').keydown(function() { $('#subtotal').text($(this).val()); });

      The field and tag are on the same page.

      Thanks!

    3. David Smith
      David Smith Staff April 5, 2016 at 11:51 am

      It will depend on the actual ID of the field that is changing. If you’re using a Calculated Product field it would be something like this:

      jQuery( '#ginput_base_price_22_5' ).change( function() { jQuery( '#secondary' ).html( jQuery( this ).val() ) } );

  52. Greg
    Greg February 25, 2016 at 2:57 pm

    Should this work when editing an entry as well? IT works well in the front end when th euser fills out the form, but if I use it in a calculation field, that value is emptied when I edit the entry in the admin.

    I am using your edit products scripts as well and if I update my quantities, the subtotal is not updated/calculated upon submit.

    Any ideas? THANKS!!!

    Reply
  53. daniel
    daniel February 11, 2016 at 8:29 am

    Hi,

    I also have the same problem as Doug, that everything slows down cause I have two calculating fields. Its a Transaction fee with 3% of the subtotal and another one for the 20% taxes. Do you have any solution for this problem? best regards and thanks for the good work, Daniel

    Reply
  54. Ozz Blayney
    Ozz Blayney February 2, 2016 at 7:14 am

    Hi There, I would like to make certain products VAT/Tax exempt within my gravity form. Do you have an equation for this? Currently I am just using {subtotal} * 0.20 but 2 of the products/services in my form don’t need VAT adding.

    Reply
  55. Christopher Naismith
    Christopher Naismith January 10, 2016 at 12:56 am

    David,

    Great stuff you have posted here. I came across this while I was attempting to pass a product ‘value’ field to another field. (ie. {Product:2:value}) Doesn’t seem to be a valid merge tag. is this something that you’ve plaid around with at all?

    Thanks,

    Reply
    1. David Smith
      David Smith Staff March 15, 2016 at 6:20 am

      What type of product is it? The value modifier is only applicable to choice-based products which support the value property on each choice.

  56. Daniel Feldbrugge
    Daniel Feldbrugge December 5, 2015 at 4:29 am

    Great script David!

    I’ve got one question. If I use {subtotal} only in the calculation of a product it refreshes the pricing. Only when I add a formula to the calculation ({subtotal * 0,019) it only shows the first selected product and isn’t refreshing the sum of the formula.

    Doe you know what is going on here?

    Reply
    1. Daniel Feldbrugge
      Daniel Feldbrugge December 5, 2015 at 4:39 am

      I’ve figured it out! It has to do on how the calculation formula was written. I’m from europe and we use , as the decimal sign. The decimal sign should be . instead :-)

  57. daniaux
    daniaux November 18, 2015 at 4:36 pm

    Hi,

    I’m using this present code to make lots of different calculations in my form. In the same time, I’m also using “Enable Decimal Values in Quantity Fields”.

    My problem is a little bit difficult to explain but i will try to do it. – My problem only exists during the data recording (I took note of this using &data=1). It’s good in the form on the web page. – When I write a quantity like 0.x, the associated price is not taken into the variable “subtotal” (using in a number field). – When I’m writing a quantity like 1.x (higher than 1), the associated price is taken into the variable “subtotal” (using in a number field).

    I hope my explanation are clear enough.

    Thanks for your help.

    Thierry

    Reply
    1. daniaux
      daniaux November 18, 2015 at 7:04 pm

      Hi

      I think I’ve solved my problem changing your code. In the following function “has_valid_quantity( $quantity_tag )”, i replaced return intval( $qty_value ) > 0; with return $qty_value > 0;

      Could you tell me if this modification is good for you or not ?

      Thanks.

    2. David Smith
      David Smith Staff November 19, 2015 at 9:33 am

      I’ve updated it to floatval( $qty_value ) from intval( $qty_value ). That should work for you too, I think. :)

  58. Howard
    Howard November 14, 2015 at 12:20 am

    Here’s a good question, can you please add this code in the regular update for gravity forms? For some unknown reason I get an error when I add the code to my child functions.php but I don’t get an error when I add it to the top of my main theme functions.php. Why?

    Reply
    1. David Smith
      David Smith Staff November 22, 2015 at 5:56 pm

      This might get incorporated into GF core eventually, for now, it’s actually available to Gravity Perks users as a plugin by request. Pick up a copy and drop me a line via support and I’ll send you the latest version.

  59. Nikolai
    Nikolai October 25, 2015 at 10:03 am

    Thank you for such useful script, but i’m not able to configure it. Once i add the price field with subtotal calculation it shows me 2 fields (my total field and subtotal) How do I merge subtotal with my total price without showing the subtotal price?

    Reply
    1. Nikolai
      Nikolai October 25, 2015 at 11:51 am

      I actually managed to fix the issues, by adding +{Subtotal1:”fieldnumber} to my product field, it now calculates. But when user checks out in paypal for example, then subtotal is not being calculated. Any idea how to fix that?

  60. Rob
    Rob October 13, 2015 at 3:36 pm

    Hi David, many thanks for writing a snippet like this, looks uber useful however when I put it in place on a form it seems to result in the total price being thrown off by varying amounts depending on which product options are selected. Also, the subtotal price doesn’t reflect what the total price is (prior to any calculations). Just want to use it to add tax to the total, any help/support etc big time appreciated. Cheers, Rob

    Reply
    1. Rob
      Rob October 13, 2015 at 5:36 pm

      Hi David, just a follow up from the last comment as I’ve been hammering away at it and read through the rest of the comments which has allowed me to almost get this over the line.

      The issue I have now is one that has been mentioned before, namely the subtotal amount is getting added to the total amount. I have tried a bunch of a variations between using products/numbers/quantities to display the subtotal (and total amount, at this stage I’ll take it any which way and style it up after) but for whatever reason just can’t get it to play ball.

      Any help on how to get around this snag would be big time appreciated..

      Thanks, Rob

    2. David Smith
      David Smith Staff October 21, 2015 at 11:11 am

      Hi Rob, the {subtotal} will only be counted towards the total if a Product field is used. If you use a Number field it will not count towards the total.

  61. Marj Wyatt
    Marj Wyatt October 6, 2015 at 8:19 pm

    This is a nifty piece of code, and I thank you so much for sharing it.

    I do have a conundrum, however. I’m using product fields to assign a price to items that people may select on my project estimator form. (I’m also a WordPress developer.)

    My idea was to use {subtotal} + the field where I’ve stored the product price. I’m using a calculations field instead of a Gravity Forms Total so I can display the final estimated price for what a prospect wants done.

    When I do this, the price assigned to that choice doubles. When I don’t use {subtotal} at the beginning of the calculation, it is fine. I was wondering if anyone else had experienced this.

    I created a hidden field at the top of the form that sets {subtotal} to zero with this formula: {subtotal} * 0.

    No joy …

    Maybe I don’t need the {subtotal} merge tag for this form and I’m over-complicating things. I’ve been known to do that. :)

    My Gravity Form is very complicated, for me. It is using a lot of conditional logic to walk prospects through scenarios that I’ve encountered in my nearly 10 years of developing with WordPress. If you want to look at the form, I’m happy to upload it to a temporary location and share that URL with you using private email. I’m not ready to show this project to the public yet.

    I’ll close this comment by thanking you, again, for sharing your brilliance. Gravity Forms is powerful but confusing when you want to do something unusual. If it weren’t for folks like you out there, I’d be thrashing for hours!

    Reply
    1. David Smith
      David Smith Staff October 8, 2015 at 5:28 pm

      Hi Marj, I’m happy you find my resources so helpful. :)

      Could you send me an export of your form with the broken field intact. Also, could you indicate which field contains the {subtotal} merge tag? Email is david at gravitywiz dot com

    2. Marj Wyatt
      Marj Wyatt October 9, 2015 at 3:03 pm

      I figured it out, David.

      In the field using the {subtotal}, I was using a formula like {subtotal}+product-field. If I leave the +product-field off, things work as you’ve explained.

    1. David Smith
      David Smith Staff October 5, 2015 at 9:42 pm

      Hi Doug, glad you’re enjoy Gravity Perks. :)

      Are you using the {subtotal} in multiple fields that have any dependency on each other? For example, two separate product calculation fields? A Calculated Number field that depends on another Calculated Number field which both use the {subtotal} merge tag?

    2. Doug Higson
      Doug Higson October 5, 2015 at 9:58 pm

      Yes – i am trying to figure out how to calculate different tax for different states (and later zip codes) It is working if you just have one state… but when I add multiple states it crashes sometimes.

      So when a user puts in order, the display shows their sales tax before checkout. Thanks again for the quick reply!

    3. David Smith
      David Smith Staff October 5, 2015 at 10:09 pm

      Hi Doug, if you’re already a Gravity Perks user, drop me a line via support and I’ll send you a copy of GP Subtotal & Tax. It adds support for Tax fields that should really make this a lot easier for you.

  62. Prayas Sapkota
    Prayas Sapkota October 2, 2015 at 12:01 am

    Hi,

    Thanks for the script. It works very well but if I use this script on dynamically populated product options field. the subtotal is not working.

    Will you please help me on this?

    Thanks, Prayas.

    Reply
    1. David Smith
      David Smith Staff October 2, 2015 at 7:25 am

      Hi Prayas, can you send me an export of your form and more details on how you are prepopulating your form?

    1. David Smith
      David Smith Staff September 28, 2015 at 8:17 am

      Hi Paul, I have a perk in the works that adds support for subtotals, taxes and both working with coupons. If you’d like to take it for a spin, pick up a Gravity Perks license in ping me via the support form.

    2. EJ
      EJ January 17, 2016 at 11:56 pm

      Hi David,

      I have the same query here: I’m using this subtotal field, it works brilliantly, but it ignores my coupon discounts. Any news on whether there is a perk that will be able to handle this? I don’t yet see one on the list, but as soon as I know that purchasing a license will give me this coupon-subtotal functionality, I’m sold!

      Thanks!

    3. David Smith
      David Smith Staff March 25, 2016 at 1:02 pm

      Hi EJ, not sure if you’ve already picked up a copy of Gravity Perks but GP Subtotal & Tax is available by request for GP license holders.

  63. Nykke
    Nykke September 27, 2015 at 8:12 pm

    Hi David,

    When I add this to my functions.php it removed all of my Custom CSS changes. I moved all of the code to my child theme style.css and almost everything works as before except for the some targeted code to change background colours. This I had to enter back into the Custom CSS plugin. But when I add this code back into the function.php it wipes it out again. Do you know of a conflict in there with the following code.

    .content { background: #ffffff !important; }

    content, .container { background: white !important; }

    body { background: white !important;}

    Reply
  64. Travis
    Travis July 19, 2015 at 9:12 pm

    Hey! This is great! Super useful. Im wondering if you can help me address a problem I’m running into. I have a long form that calculates a repair estimate and I use your snip to add 20% to the bid. However I also want to do more math with the total in other calculation fields. What happens is the first subtotal field adds in the second calculation fields resulting in a hilarious balloning estimate. Any ideas on how to prevent this?

    Reply
  65. Andre Malenfant
    Andre Malenfant July 15, 2015 at 3:53 pm

    Hi, I just finished configuring this snippet for sales taxes calculation but just realized that the CPU gets maxed out in the browser. It goes back to normal when the tag is removed… Can you give me some direction to troubleshoot?

    I use two fields with the following formulas:

    ({subtotal} – {Inscription Γ  titre de membre stagiaire de la FΓ©dΓ©ration de Voile du QuΓ©bec (Prix):16.2} – {TVQ (9.975%) (Prix):24.2}) * 0.05

    ({subtotal} – {Inscription Γ  titre de membre stagiaire de la FΓ©dΓ©ration de Voile du QuΓ©bec (Prix):16.2} – {TPS (5%) (Prix):23.2}) * 0.09975

    If I simplify the calculation it still spins….

    To test it out yourself:

    http://dev.ecovoile.com/inscription-croisiere/

    Reply
    1. David Smith
      David Smith Staff July 16, 2015 at 12:45 am

      Generally this is caused when you have many, many product fields that must be accounted for in the calculation. Can you send me an export of your form? I’ll be happy to take a look locally and see if there is anything that can be done.

    2. David Smith
      David Smith Staff July 21, 2015 at 11:19 am

      Hi Andre, I spent some time with this issue this morning. The problem is that you’re subtracting a field that uses the {subtotal} merge tag from in a field with a calculation using the {subtotal} merge tag. This is creating an infinite loop. When Field A changes, it triggers a change in Field B, which triggers a change in Field A, etc.

      In order to better support this via the {subtotal} merge tag, there would need to be an ability to exclude a field (without subtracting it) so the calculations could be done independently of the other field. This is something that I am working on in my upcoming plugin GP Subtotal & Tax.

      With that said, the GP Subtotal & Tax plugin could actually meet your needs a lot easier because it actually has a Tax field built-in. It supports multiple Tax fields as well. If you’re interested in giving this plugin a shot, just pick up a copy of Gravity Perks and drop me a line via support. I’ll be happy to give you the latest beta.

    3. Andre Malenfant
      Andre Malenfant July 21, 2015 at 11:21 am

      Ah shoot! I should have figured it out… Thanks, will take a look at the perks to see if my client could benefit from them…

      Thanks for your support!

    4. Sebastien Leblanc
      Sebastien Leblanc July 21, 2015 at 11:38 am

      David, we decided to go with the Perks. I just purchased an unlimited copy with the company address. Please send me the beta when you have a chance! Thanks!

  66. foxpc
    foxpc July 12, 2015 at 1:48 am

    Hi, great snippet thanks!

    i have one question. i want to show one total price before the “vat” for example: 100 ( don’t add to this total the snippet) 10 (vat 10%) 110 (total include vat)

    how can i make this work?

    Thanks

    Reply
    1. David Smith
      David Smith Staff July 14, 2015 at 11:39 pm

      Easiest way is to use a Number field and enable calculations. You can use the {subtotal} merge tag to output the price here. The Number field also supports formatting the number as currency. With a little styling, you could get this to match the look of the Total field.

      Edit: I just whipped up some styles to assist with this. Just add “gf_price” or “gf_total” to your field’s CSS Class Name setting to style your Number field like a total field.

      https://gist.github.com/spivurno/0dfe3bc4bcdc4e96b975

  67. paul
    paul June 23, 2015 at 3:02 am

    hi sir,

    just want to ask.

    i have this fields called product, subtotal and total, when someone choose a product, the subtotal should add 2 on it, this works on subtotal but the total field will not add the value of the subtotal.

    Product Price: $3 Subtotal: $3 + $2 = $5 Total: $3 – it doesnt add the $5

    may i know how can i add the calculated field to the total field?

    thank you for your help.

    Reply
    1. David Smith
      David Smith Staff June 23, 2015 at 6:09 am

      Hi Paul, are you using a Calculated Product field with the Subtotal rather than a Number field?

  68. sven
    sven June 22, 2015 at 5:51 pm

    hi, any idea why it doesnt add to the total… It shows in the list, but doesnt add to the total, only when you checkout it adds….

    Reply
    1. sven
      sven June 23, 2015 at 6:30 am

      I have changed it and deleted all the options, to get a better view on this. I used the code above in my functions.php (Subtotal Merge Tag (for Calculations))

    2. sven
      sven June 23, 2015 at 6:32 am

      o, and I use the product field… In the checkout, it seems it are 2 different products and calculated together in checkout… (I can also not choose to add the tax to the main product, as they are both a product…

    3. sven
      sven June 24, 2015 at 6:52 am

      So, I found the solution by rebuilding the complete form.. The fact is that you can not link this to a price option field , but you have to link this directly to the product field in order to get it calculated into the end total..! If you link it to a price option field, it’s been seen as two different products which gets calculated together at the checkout, but not in the total of form itself. By linking it to the product field, it’s been calculated together in the end total! Hope this makes sence for anyone who had this before… ! (maybe you told this before and I missed it, could also be ;) )

  69. Alex
    Alex May 21, 2015 at 11:27 pm

    Hi David,

    Great article Thank you!

    Do you know who we can set values for dropdown or radio fields? E.g if customer selects Yes in a dropdown it give them a score of 5 and then the number calculation will add up all the dropdowns ogether and add it to the total?

    The dropdowns are just general questions that we score.

    Hope that makes sense. (Because we will then send anyone with scores over e.g 20 to a different email address).

    Would love your help please.

    Cheers, Alex

    Reply
  70. DANIAUX
    DANIAUX April 26, 2015 at 11:22 am

    Hello !

    I’ve a problem with your code since i updated my wordpress theme (Divi).

    I’ve a blank page (functions.php error) and there is only this code in the code source

    [code removed]

    The PHP debug gives me the error is the following one :

    [26-Apr-2015 14:46:25 UTC] PHP Fatal error: Cannot access self:: when no class scope is active in /home/xxx/public_html/wp-content/themes/Divi/functions.php on line 4905 [26-Apr-2015 14:46:47 UTC] PHP Fatal error: Cannot access self:: when no class scope is active in /home/xxx/public_html/wp-content/themes/Divi/functions.php on line 4905

    When I delete the following code, my website works normally once more but obviously not your hook.

    [code removed]

    Thanks a lot for your help.

    Thierry

    Reply
    1. David Smith
      David Smith Staff April 26, 2015 at 7:59 pm

      Hi Thierry, I’m not able to recreate this issue. If you remove just the

    2. Daniaux
      Daniaux April 27, 2015 at 3:05 pm

      Thanks a lot for your very quick answer but unfortunatly it doesn’t solve my problem.

      I had already tried your solution but it didn’t work. It’s a little bit strange because your code in the script balises only serves in display. I’m going to look for reasons in the funtions.php file and try identifying the differences before/after the update of my themes.

      Thks

      Thierry

  71. Anthony Hortin
    Anthony Hortin April 20, 2015 at 10:36 pm

    Just used this for a form where I needed to calculate a 10% discount for members. Worked perfectly! Thanks heaps!

    Reply
  72. Jeremy
    Jeremy March 19, 2015 at 1:22 pm

    Hello David,

    Is there a snippet to support radio or check boxes. They are supported in Calculations as of 1.9?

    Thanks

    Reply
  73. Chris
    Chris March 10, 2015 at 2:19 am

    This snippet is very close to what I am looking for. All I want to do is take a value entered into a quantity field, multiply it by a number (i will input this number) and display it in an html block. How hard would this be to accomplish?

    Reply
    1. David Smith
      David Smith Staff March 10, 2015 at 8:21 am

      Hey Chris,

      What I’d do is use a Calculation field to calculate the number (the Quantity input is accessible via merge tag in the calculation). You can then add a <span> to your HTML field, give it an ID, and then bind a jQuery function to the change event of the calculation field so any time it changes, you can populate the span with the updated value.

  74. Oscar
    Oscar February 13, 2015 at 7:03 am

    Hey this is an awesome snippet! I have a question with this form here that I’m developing: http://velting.com/test-form/ and I need to enable a calculation field in a list field. In this example I explain that I need to do a calculation between the Material * Total Tones.

    Can you help me please??

    Reply
    1. Oscar
      Oscar February 13, 2015 at 1:17 pm

      Hey awesome!! Im seeing this snippet, definitely it has what I need. Just a quick question, what should I need to edit to get to multiply two of my columns?

  75. GD
    GD February 12, 2015 at 12:46 pm

    I tried installing this but also received errors like the other users mentioned. It appears that there are two of these tags in the snippet: <?php

    Do we remove both of them? I have installed the snippet in the theme’s functions.php file.

    Reply
    1. David Smith
      David Smith Staff February 13, 2015 at 7:59 am

      You should only need to remove the <?php tag that is at the top of the snippet, not the <?php tag that is at the top of your functions.php file. Let me know how it goes.

  76. Andy Symonds
    Andy Symonds January 30, 2015 at 8:34 am

    Thanks so much for this David. I can’t believe this isn’t built into Gravity forms by default as it’s such an obvious piece of data that should be available to Gravity Form admins giving them the ability for example to display per person prices for group tours etc.

    Reply
  77. Stefan
    Stefan January 30, 2015 at 5:36 am

    Hi folks. Instead of meddling with the theme’s functions.php you can also install the code snippet plugin, add a new snippet, paste the code for your subtotal merge tab, save and activate, done. I just tried. Works fine. Plus: you don’t have to worry about updates anymore. Stefan

    Reply
    1. David Smith
      David Smith Staff January 30, 2015 at 7:22 am

      Agreed. One big warning. In some cases (not with this specific snippet), you’ll want to apply the functionality to multiple forms. Do not include the entire snippet multiple times. You will get a fatal error even with the Code Snippets plugin. You just duplicate the configuration code at the very bottom of the snippet.

  78. Nadeem Shaikh
    Nadeem Shaikh December 29, 2014 at 1:15 am

    Many thanks for code you have shared but somehow it is not working for me.

    What all I have done – I have watched the Snippet installing image & followed it exactly. I am pasting the code in the theme functions.php (correct file) if I don’t remove php tags from above code from line 1 & line 225, I get 503 error. If I remove them, code gets installed but {subtotal} is not visible in Merge tabs dropdown.

    I have tried on New form as well but it the subtotal is not visible in Merge tabs.

    i have added a Number filed & have clicked on Calculation. I am trying to divide Grand Total with Quantity so that I can get Price per Quantity.

    Form Page – http://www.biryano.com/order-page/

    I have created form in 4 pages and in the 4th page I need Price per Guest which comes as Zero.

    Please assist.

    Reply
  79. Ann Marie
    Ann Marie December 11, 2014 at 1:20 pm

    Bummer I could really use this snippet, but blank page after i paste into bottom of functions.php file. It is indeed in the correct theme file – not wp-includes

    Reply
  80. Angel
    Angel November 19, 2014 at 6:43 pm

    Hey, this works great! I am not sure if this is what I need. I want to make a monthly/annual selector for the final price. So Now i have some options and that gives me a total price. I want a selector at the end that allows me to choose that price for monthly or a 12X for anual payment.

    How do you think this can be made?

    Thanks

    Reply
  81. Cristina
    Cristina October 29, 2014 at 5:19 am

    Hello,

    I’ve tried to add a new functionality to the Gravity Form plugin by copying this code into functions.php file and all I got was a blank screen. I have managed to remove the code via FileZilla, but the pages are still blank. I have replaced the file with a new one, I have renamed the plugins, themes, increased the memory, changed the folders and files permissions, and it still doesn’t want to work.

    How can I fix it?

    Website: http://eptestsite7.co.uk/. WordPress: 4.0. All the other plugins and themes are up to date.

    Many thanks in advance! Regards, Cristina

    Reply
    1. Cristina
      Cristina October 30, 2014 at 9:24 am

      Hi,

      Me again. The old problem is solved now and the code for doing the subtotal calculations is in, but it throws out an error when I try to preview the form and breaks out my entire layout. Here is a link to the form: http://www.eptestsite7.co.uk/?gf_page=preview&id=11 and here is the product to whom the form has been assigned: http://www.eptestsite7.co.uk/product/compliment-slips/. It seems that the GFCoupons function is causing the problem. Can you pleas help me to solve it?

      Many thanks! Regards, Cristina

    2. David Smith
      David Smith Staff October 30, 2014 at 9:57 am

      Oops! I reverted back a version. The coupon functionality is not ready for the public yet. This version will work as expected but does not support discounting coupons from the subtotal.

  82. Aaldrik
    Aaldrik October 27, 2014 at 5:19 pm

    Hi there,

    Question. My english is not the very best, so I don’t know if this is the right solution for me. I want to add my product at a calculation field. The only field who can calculate now is the number, but I want to calculate a product * 12, or 6 or 3. Is this possible with this code?

    Reply
    1. David Smith
      David Smith Staff October 27, 2014 at 6:03 pm

      This merge tag will calculate the total order and allow to use that number in your calculations. If you want to calculate a product price, you should be able to do this without any custom code. Just add a Product field to your form select “Calculation” from the Product Type setting.

  83. Mike
    Mike October 10, 2014 at 1:00 pm

    I tried this twice at the bottom of function.php, one with the leading <?php, and again without, both time the site goes white?

    Reply
    1. David Smith
      David Smith Staff October 10, 2014 at 10:36 pm

      Hi Mike, make sure you’re adding this to your theme’s functions.php and not the wp-includes/functions.php.

    2. Michael West
      Michael West October 12, 2014 at 12:12 am

      Hi David, thanks for the reply. Sure enough, I was putting it in the wrong place ;-) Works well now, thx. Was able to get around the issue of it adding the tax (which is a product) to the sub-total, by subtracting it in the formula box.

      subtotal =(subtotal-tax) tax=subtotal x5% total=subtotal+tax

      Will be looking at your Perks, is there a list for updates?

      Mike

  84. Dolmat
    Dolmat October 8, 2014 at 11:09 pm

    Is this hack only beneficial when we want to display something like tax? (like in your Demo) How about to show the current subtotal for certain section in the form? For example this is my form:

    SECTION A – Principal membership plan

    Plan 1 – $100 Plan 2 – $200 Let say i choose Plan 1, so its $100

    SECTION B – Supplementary membership

    Plan for spouse – $80 Plan for child – $50 Let say i choose both plan, so its $130

    If using only Total field, it will show just Total = $230. Or maybe before the Total is Tax just like in your demo. Can i show it like this instead?

    SECTION A subtotal = $100 SECTION B subtotal = $130 TOTAL = $230

    Reply
  85. LV
    LV September 27, 2014 at 5:36 pm

    A HUGE shout out to David! He’s very helpfull, assisted me perfectly and replied very fast! Once again.. Thank you so much for all the time you invested and the great service!

    Reply
  86. LV
    LV September 27, 2014 at 1:39 am

    Hi David,

    <

    p>So sorry, but I might have missed that Request? Is the answer on the forum or did you sent me a private email? Can you please tell me once again what information I need to provide? Because You’ve sent me a link and still coudn’t figure out the right formula

    Reply
  87. LV
    LV September 26, 2014 at 6:42 am

    Hi David,

    I’ve been breaking my head over the calculation formula and I really hope you can help.

    This is my commission list:

    < €1.000 15% € 1001 – € 1500 12% € 1501 – € 2000 10% € 2001 – € 2500 8% € 2501 – € 3000 6% € 3000 > 4%

    I just can’t seem to figure out where in the code I need to Place the amount and if I use a > it doensn’t Work.

    <

    p>I now have {amount:2} * 85 This should be For the first option (€0 > €1.000 = 15%) I’ve searched For 4 days and I can’t seem to find an example. Can you please help

    Reply
  88. Ronnie
    Ronnie September 25, 2014 at 4:46 pm

    Hello, I’m trying to deduct a percentage from the total amount. Currently I’m using .8 * {total} in my calculation field to generate the price at 20% off. Can you tell me what I am missing because it is not working.

    — Ronnie

    Reply
    1. David Smith
      David Smith Staff September 25, 2014 at 10:06 pm

      Hi Ronnie, with this snippet you can use a {subtotal} merge tag. If even that is not working for you, include a URL in your response where I can view the form.

  89. Alexander Kohl
    Alexander Kohl August 18, 2014 at 10:32 pm

    Thanks for the great snippet. It does not seem to take the result of a coupon field into account. Is that supposed to happen? Alexander

    Reply
    1. David Smith
      David Smith Staff August 21, 2014 at 9:31 pm

      Hi Alexander, I have not had a chance to test this yet… but I believe you are correct. I’d love to add support for this as time allows. I’ll let you know when this is added.

    2. Alexander Kohl
      Alexander Kohl August 21, 2014 at 10:47 pm

      Thanks David, we had a bit of a look but could not figure it out,because that coupon field behaves so differently to other fields. Alexander

  90. Steven Records
    Steven Records August 7, 2014 at 5:49 pm

    Thanks for the code it got the functionality working just now I am receiving this:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/content….php:2) in /home/content……php on line 32

    Any thoughts?

    Reply
    1. David Smith
      David Smith Staff August 8, 2014 at 11:32 am

      Hey Steven, if you remove the snippet does the issue go away? If yes, can you add the snippet back and provide 1) a url where I can see this issue and 2) the complete contents of your functions.php file (use a pastie)?

  91. Andreas
    Andreas July 7, 2014 at 1:06 pm

    Hi!

    The subtotal string is a cool feature bringing me one step closer to my goal :-) But I’m still looking for a tip how to create an order form that matches german legal standards.

    On the checkout page I have to display (a) the number of products ordered (b) the price of a single product (c) the subtotal without VAT (which equals (a) * (b)) (d) the VAT (which equals (a) * (b) * 0.19) (e) the total incl. VAT

    (b), (d) and (e) are easy to set up, especially with the subtotal merge tag for (d). But when adding the subtotal tag for (c), the total in (e) is no longer correct.

    Does anyone have an idea how to create the order form?

    Thanks!

    Reply
  92. Jay
    Jay June 19, 2014 at 5:03 pm

    Hi David,

    I’m so glad that I found your snippet which I think will perfectly work for my needs. I just have a question about the way I’m missing on how I can implement on my site. Once I add calculation field on the form and using the formula as below, I was expecting the subtotal value updates with the amount stored {Option Total:13} and pass over the final subtotal value to the total amount in woocommerce plugin. Total amount in the cart still missing the value in {Option Total:13} in the cart. Could you please advise me if I’m missing anything? Many thanks in advance.

    {Option Total:13} + {subtotal}

    Reply
  93. Robert
    Robert June 13, 2014 at 11:20 am

    Hi,

    I’m wondering if this code can help me at all? I don’t believe so…but maybe? I have a 4 page form, and it has products that cost money on 2 of the pages. (pages 2 and 3). What I want is to show the full price for all the items chosen, but I want to only collect 25% of that amount when they click the submit button on last page (through paypal). It’s a deposit so that’s why the amount is not the same. So I wanted to have a total field, then under it a field labeled “Total Deposit Amount” and then it would be just subtotal * .25. I can’t figure out how to do this. What kind of field should I use? I setup with a product field set to type calculate, then disabled quanity and entered the formula, but it always shows the full price in total field, $0 in the field using the subtotal calculation, and always tries to charge the full amount in paypal.

    Reply
    1. David Smith
      David Smith Staff June 13, 2014 at 11:49 am

      Hi Robert, it sounds like the easiest way to accomplish this is by adding a Calculation Product field and using - ({subtotal} * -0.25) as the formula. This will create a negative number which will then be deducted from the total.

    2. Robert
      Robert June 13, 2014 at 10:40 pm

      Hi David,

      Thanks for the reply. I just tried that but I changed it up a bit…here is what I did. I know the subtotal code is ok in my functions.php because it shows up in the merge tags.

      Just before the bottom of my form, I now have a hidden field, and set to calculation, then the formula is:

      ({subtotal} * -0.75)

      Then after that field, I have a normal total field. So that should take 75% off the total and leave me with 25% of the original total right? But it’s ignoring the hidden field. It just keeps showing the actual total. Even when I only pick 1 product the price ends up showing the full product price.

      Any idea what’s going on?

    3. David Smith
      David Smith Staff June 14, 2014 at 7:40 am

      Hi Robert, did you try my suggested approach first? If not, give it a try and confirm.

  94. selorm branttie
    selorm branttie June 12, 2014 at 8:27 am

    This is certainly helpful, but I was wondering if this code could be used to say make a calculation involving an external shortcode?

    In this case I want to convert currencies dynamically using another plugins shortcode, and my form has front end price input for custom products. What I want to do is create a total value based on the current prevailing exchange rate as well as the subtotal at the end of the form.

    Is there any way this can be done?

    Reply
    1. David Smith
      David Smith Staff June 14, 2014 at 8:24 am

      Hi Selorm, I’m sure it is possible to accomplish given Gravity Forms vast number of hooks. This probably isn’t something I’d be interested in tackling in relation to this article.

  95. Ed
    Ed June 4, 2014 at 3:19 pm

    Hi, I was wondering if it is possible to add a service charge as well? I currently have the following formula for my tax {subtotal}*.06 Works great! What I am needing now however is an additional .18 % on top of that formula total. So I created another field and have been playing around with the formula but no luck. Any ideas? Thanks!

    Reply
  96. Eva
    Eva June 1, 2014 at 5:34 am

    Hi David, this is exactly what I need for my form! Thank you very much! Like others said before: a life and time saver:). Calculation with subtotal works very well. I used it in a hidden calculation field to calculate a tax (({subtotal} / 1.19) * 0.19), because I need the value only in my “Thank you”-email.

    Unfortunately my browser slows down dramatically and my CPU is at 50% load and sometimes the site stopps and I got a message of a not answering script: (I translate to English) A script on this site is probably working or it does not answer anymore. You can stop the script or continue, to see if the script has finished.

    Script path in preview site: http:/domain.com/wp-includes/js/jquery/jquery.js?ver=1.11.0:2 Script path on website where the form is implemented: http:/domain.com/wp-content/plugins/gravityforms/js/gravityforms.js?ver=1.8.8.2:30

    (In German: Ein Skript auf dieser Seite ist eventuell beschΓ€ftigt oder es antwortet nicht mehr. Sie kΓΆnnen das Skript jetzt stoppen oder fortsetzen, um zu sehen, ob das Skript fertig wird.)

    I need this subtotal calculation and have to create another one to calculate a new tax, so it would be very impotant for me to get help here.

    I pasted the code into my functions.php of my child theme after the code snippet “customizing-gravity-forms-user-registration-activation-page”.

    Thank you, Eva

    Reply
    1. Eva
      Eva June 1, 2014 at 6:06 am

      Addition: I made some tests and the result is: the more I use the subtotal merge tag in different calculations, the slower the site gets/stopps completely and I have to restart the browser. Right now I calculate 5% discount if you register more than 1 person. If you register more than 1 person and you have a coupon code, you get 15% discount (2nd calculatiob with condition), if you register 1 person and have a coupon code, you get 10% (3rd calculatiob with condition). In all these fields, I use the subtotal merge tag. In addition, I need it for 2 hidden calculations for the taxes. Perhaps it is too much? Is there an other solution for this?

      Thank you very much in advance, Eva

  97. Steve
    Steve May 6, 2014 at 3:57 pm

    Sincerely, thank you for writing this plugin, you have saved me an enormous amount of time. Honestly, I couldn’t be more grateful. Is there a place I can donate?

    Reply
    1. David Smith
      David Smith Staff May 6, 2014 at 6:23 pm

      Glad to help. Feel free to send any donations to david at gravitywiz dot com via PayPal though the best way to donate is to buy Gravity Perks! :)

  98. Matt Cassarino
    Matt Cassarino May 2, 2014 at 11:36 am

    Great snippet though its use seems limited. Initially, I was trying to setup both a subtotal and a total field, but the total was being doubled because it was including the subtotal, as follows:

    • subtotal was product field with calculation, using your awesome snippet
    • total was total field, with its value being doubled (it was counting all fields including the subtotal thus showing exactly double the total value)

    Following your example form, I ended up scrapping my subtotal field and using the subtotal to generate a tax amount (hard-coded for now at 9.5%). This works great.

    Now I’ve just gotta figure out how to allow the user to enter their appropriate tax rate. Thinking of using a dropdown for them to select their tax, ensuring consistent tax format. Any suggestions?

    http://www.alpinemarkings.com/school-supplies-reorder-form/

    Thanks again for your contribution to making GForms better!

    Reply
    1. David Smith
      David Smith Staff May 30, 2014 at 6:32 pm

      Hi Matt, it sounds like what you need to be able to do is exclude the other “subtotal” field from the calculation of the latter “subtotal” field. Definitely something I’m interested in adding. No ETA.

      Using drop down to allow the user to select the tax rate sounds ideal. :)

  99. Kristen
    Kristen April 18, 2014 at 5:38 pm

    Hi David, I have the subtotal merge tag now but I can’t get it to work the way I want it to. I am trying to create an order form. I want the subtotal to add up all the fields except tax and shipping but its adding ALL the fields up. I created this formula to get around it: {subtotal}-{Tax (Price):40.2}-{Shipping:41}. That formula does the trick but then the tax is double what it should be. I have this calculation in tax field: {subtotal}*.07. Is there a better way to get the subtotal to add up everything but tax and shipping?

    Reply
    1. David Smith
      David Smith Staff April 18, 2014 at 5:59 pm

      Hi Kristen, if you’re using the latest version, shipping should not be included in the subtotal by default. Do you have a URL where I can view this form?

    2. Kristen
      Kristen April 18, 2014 at 10:07 pm

      Yes, I have a URL where you can view the form but I rather not share it on this thread if you don’t mind. It’s for my clients eyes only. Thanks!

      [removed]

  100. Stuart
    Stuart April 8, 2014 at 11:44 am

    David,

    Great snippet. Worked like a charm for me. I used this to create a promo code option. Opposed to adding on to the total, I used it like this: -({subtotal} * .1) in conjunction with a text field and a product field at the very end of my order form. If the client enters the correct text, conditional logic pops up the discount amount and applies it to the final total. Super slick and so much easier than every other method I had been trying.

    Thanks!!! Stuart

    Reply
    1. David Smith
      David Smith Staff April 4, 2014 at 3:37 pm

      Hi Taylor, try removing the opening <?php tag (from the snippet) and make sure you’re running the latest version of Gravity Forms.

  101. Ed
    Ed March 31, 2014 at 3:27 pm

    Just wanted to say thank you! I had been looking for something like this for quite some time and Rob at Gravity Forms guided me here.

    Reply
    1. David Smith
      David Smith Staff March 17, 2014 at 3:38 pm

      Hi Paul, I’ve updated the code to resolve this issue. The demo should work correctly now. Thanks for letting me know. :)

  102. wunderdojo
    wunderdojo February 13, 2014 at 8:32 am

    Did a quick Google before settling in to code something and came across your post. Exactly what I needed and works perfectly. Thanks a ton for sharing this.

    Reply
  103. sven
    sven February 4, 2014 at 6:17 am

    Hello

    i am using this snippet, like this I have 1 field with subtotal wich gets the total price of all products. And the second one i try to make {subtotal} * 0.2 for the taxes but the calculation i get is wrong

    Reply
  104. Lev
    Lev January 28, 2014 at 11:39 am

    Hi I have question I have a drop-down list with prices, IE item 1 $10.00,item2-$15.00 and so on at the end of the form I need to calculate sales tax so your snipped should be a life saver and it appear in calc tag selection , however Total field see and display selected item price subtotal do not see selected item price.

    Any suggestions?

    Reply
  105. Alex
    Alex January 22, 2014 at 3:52 pm

    i just added your hack to gravity form. However, when i try to do a custom price with subtotal.. the total is not good.

    eg : field01 is radio button, with $2 and $0

    ({subtotal}) + ({field01 10A:59})

    when i put radio on $2, the subtotal is wrong.

    its wierd, cause if i just put ({subtotal}) i got the good price without field01.. and if i put ({field01 10A:59} without subprice i got the good price… but if i do an addition : wrong :/

    Reply
  106. Vanessa
    Vanessa January 16, 2014 at 7:15 pm

    Hi, thanks for this. I assume that the subtotal merge tag goes into the Number field? If so, it spits out the subtotal within an input field, and does not have a $ next to it. Is there a way to display the Subtotal as in $0.00 format with the dollar sign and as text instead of within an input field?

    Reply
    1. David Smith
      David Smith Staff January 17, 2014 at 7:48 am

      Hi Vanessa, this merge tag would go into the “Formula” setting for Calculation-enabled Number and Product fields. The formatting of the returned number is dictated by the field. For number fields, it will not have the money sign. For product fields, it will.

      Is there a way to display the Subtotal as in $0.00 format with the dollar sign and as text instead of within an input field?

      Could you clarify what you mean here? I’m not sure I follow.

  107. Jagesh
    Jagesh January 10, 2014 at 10:16 am

    Hi,

    Is it possible to show calculation field type as checkbox in gravity form. by default its adding to the product.

    but i want to show this field type as checkbox with calcualtion. so that it will show dynamic price.

    Please advice asap.

    How to register in your site?

    Thank you!!

    Reply
    1. David Smith
      David Smith Staff January 10, 2014 at 9:21 pm

      Hi Jagesh, I’ve seen similar requests for checkbox products come up before. I don’t have a ready solution for this yet but I’ll keep it in mind for a potential snippet.

  108. Emil Eriksen
    Emil Eriksen December 9, 2013 at 12:51 pm

    Hi,

    Thanks for this great snippet! It’s a real time saver.

    I have a small problem though. Basically I have a sub total field (no tax – number field), a tax field (product calculation field) and a total field. In order for the sub total field to not include the tax product field I’ve simply divided it by my tax rate ({subtotal}/1.25) which works excellently. However when I include my sub total field in a notification email it doesn’t give me the number from the form but the number / 1.25 (so I get ({subtotal}/1.25)/1.25).

    I hope you can understand my explanation :)

    Reply
    1. David Smith
      David Smith Staff December 9, 2013 at 2:41 pm

      Hi Emil, the {subtotal} merge tag is only supported in the Formula setting for Calculation fields. If you want to use the Subtotal in a notification or any other place post-submission, you’ll want to create a Number field with calculation enabled, use just the {subtotal} merge tag for the formula and then use “gf_hidden” to hide the field from the customer’s view. You can then use the merge tag for that field (something like {Field Label:2}) and it will display the submitted Sub Total value.

    2. Emil Eriksen
      Emil Eriksen December 9, 2013 at 3:18 pm

      Thanks for the reply!

      I am using a Number field that displays the sub total and {Number field name:x} in the email notification but because I divide the sub total with my tax rate it seems that this calculation is repeated when the email is sent. So for instance the sub total field would display 100 when filling out the form (and would be calculated (all product prices + tax product price)/1.25). I divide it by the tax rate because I want to display sub total without tax and a total field with tax. In the email it would then display 80 (100/1.25). This image should explain how my fields are set up: http://i40.tinypic.com/2m41w74.png

    3. David Smith
      David Smith Staff December 9, 2013 at 5:54 pm

      What do you want to display in the notification? The Subtotal or the Subtotal with Tax? The {subtotal} merge tag is only available for calculations. It can’t not be used in the notification email. If you want to display the submitted entries subtotal, you’ll want to capture the subtotal in it’s own field (see my instructions above about adding an extra Number field to store the subtotal with the entry) and then use that field’s merge tag to display the captured value. Hope that makes more sense. :)

    4. Emil Eriksen
      Emil Eriksen December 10, 2013 at 4:00 am

      Hmm, this is difficult to explain… I’m not using the {subtotal} merge tag in the email notification. I’m using (from my screenshot) field 73. Say I had two products with a price of 50. In the form I have the three fields; sub total, tax and total. Tax would display 25 (25% tax), total would display 125 and sub total would display 100 which is great – just what I want. The issue is when the notification email is sent. Tax will still display 25 and total 125 but sub total would display 80 (100/1.25) instead of a hundred like it does when you fill out the form. This seems to be a bug caused by dividing {subtotal} with 1.25 like I do in the number field (ID 73).

      I hope you get the idea.

  109. scott
    scott November 23, 2013 at 12:34 pm

    Hi David

    Thanks for this! Life saver. Crazy Question. Is there a way to add ANOTHER subtotal merge tag to the script? I’m working on a screen print shirt calculator. Basically, I’ve used your subtotal merge tag to output the final cost of the shirts x the number of locations… which gives me a price PER shirt. Now I need to let the user calculate the price PER shirt x the TOTAL amount of shirts they need. For instance {subtotal2}*{Total Quantity:20}

    Does this make sense? It’s getting complex :)

    Scott

    Reply
    1. David Smith
      David Smith Staff November 23, 2013 at 5:33 pm

      Hi Scott, there is no hard limit on how many {subtotal}-based calculated number/product fields you can have on the form though I agree it does get kind of complex… but hey! It might work. :)

  110. Raphael Essoo-Snowdon
    Raphael Essoo-Snowdon November 11, 2013 at 10:43 am

    Version: 1.7.12

    Having the same problem of the “Subtotal” merge tag not being available from the select menu.

    • Pasted code into theme’s functions.php
    • Added Number field
    • Enabled calculation

    Still can’t see the “subtotal” field in the “Insert Merge Tag” dropdown.

    Any ideas?

    Reply
  111. Ryan Wignes
    Ryan Wignes October 24, 2013 at 12:45 am

    Thanks David but when I enter the snippet, it does not create a “subtotal” merge tag like it should. Any reason why this could be?

    Reply
    1. Brian
      Brian October 9, 2013 at 5:43 pm

      Aha, I got it to work by typing {subtotal} instead of {Sub Total:61} which had appeared in the Merge list.

      Is there any way for this subtotal field to be reduced by a Coupon/Discount code?

      The “Total” field works great but I’m trying to duplicate this for the Stripe Add-On…

      Thanks Brian.

  112. Elin
    Elin October 5, 2013 at 10:08 am

    Hi David

    Your Snippet is right the thing what I’m looking for. I have copied the code into my function.php but i can’t find the “subtotal” button now.

    Can you help me? What have I done wrong?

    Thank you Elin

    Reply
  113. Elin
    Elin October 5, 2013 at 10:06 am

    Hi David Your snippet is right what I’m looking for. I have copied the code into function.php. But how does it work now? I cant’t find the “subtotal” button.

    Thank you for helping me Elin

    Reply
  114. Sean
    Sean September 30, 2013 at 9:46 am

    Hi David,

    Pasted this in functions.php as it it (at the bottom) and it returns told me to remove the < at the start, other than that see no option in the drop down for subtotal, wonder what I am doing wrong? :)

    Reply
    1. Sean
      Sean September 30, 2013 at 10:13 am

      Hi David,

      Great snippet! Seems to work perfectly, but I get a headers error when using this…

      Warning: Cannot modify header information – headers already sent by (output started at …/functions.php:135) in …/woocommerce/classes/class-wc-session-handler.php on line 63

      Any idea? Maybe I am adding it wrong? :)

  115. Ben
    Ben September 2, 2013 at 2:00 pm

    If I set up a numberfield for calculation and enter ther {subtotal} I have not exactly the same values as my products have. Whats going wrong?

    e.g. subtotal of product ist: 823,53 € and the numberfield makes 831,7653 out of it?

    Why??

    need help, urgent…

    best regards, Ben

    Reply
  116. Ben
    Ben September 2, 2013 at 11:01 am

    I have added a subtotal calculation into my form in order to calculate add value tax/sales tax. Unfortunately the values of the calculation are not showing up on my confirmation page. Instead it puts … I have: {subtotal} * 0.19

    I lists my product and under it the second product (tax), quantity both 1 but tax value is 0,00€ :(

    How can I fix this?

    best regards, Ben

    Reply
  117. Gravity Forms for Ecommerce with tax and shipping options | Ari Salomon: Art and Design August 25, 2013 at 11:49 pm

    […] I found this bit of free code from GravityWiz that gives you a ‘subtotal‘ field – I have not tried it but looks like a simpler solution that saves lots of work […]

    Reply
  118. Thomas
    Thomas August 6, 2013 at 6:48 am

    Hi all,

    I want to change the color of the subtotal, but I do not understand when it is called in the css code … I would like to do called CSS Total. Is this possible?

    Reply
  119. Andrew Blackburn
    Andrew Blackburn July 26, 2013 at 1:34 pm

    David, interestingly, I think there is a bug when you use a hidden product field with the quantity box disabled (at $0.00 price). There is an “options” product field on my form with several different check-boxes to add things to the subtotal. My calculation field is the subtotal divided by 2. However, with the configuration I told you about above, the price starts at $0.50 before I even add anything. It should start at $0.00. Another odd issue is when I add certain options to my hidden product it doubles and even triples the price. Do you think I am doing anything unintended or wrong?

    Reply
  120. Andrew
    Andrew June 27, 2013 at 3:13 pm

    Really useful, but I’ve run into the issue of this code lagging the browser as it tallies every one of my 50 or so products.

    Is there any way to alleviate the lag?

    Reply
  121. jimmy
    jimmy June 26, 2013 at 9:47 am

    i try to use it but it return me an higher value, i dont understand why, i use it in a calculation product field

    Reply
  122. Drew R
    Drew R June 14, 2013 at 11:09 am

    Is there a way to make the subtotal calculation functional but hidden. For example, I am trying to use the subtotal as a commission field and I want to have the subtotal multiplied by a certain percentage just like you have in your illustration but I don’t want it to be visible to visitors on my site while being calculated in my total function.

    Reply
  123. Robert
    Robert June 14, 2013 at 7:22 am

    David,

    2 things. First shouldn’t there be a ?> at the end of the code in your example?

    The other thing is…I’m using a child theme so when I get updates to my theme, it won’t mess with my customizations (like your code), but when I saved it in my functions.php for the child theme (both with and without the closing ?>) I get an error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/79/9416879/html/sitename/wp-content/themes/your-child-theme/functions.php:26) in /home/content/79/9416879/html/sitename/wp-includes/pluggable.php on line 876

    Any ideas?

    Reply
  124. Zuke
    Zuke May 30, 2013 at 11:07 am

    David this is great, thank you. One thing i cant do is add the merge tag in confirmations or notifications. Is that not possible?

    Reply
    1. David Smith
      David Smith Staff May 31, 2013 at 10:01 am

      Hi Zuke, this merge tag is only available for calculation fields; however, you could probably add a Number field and enable the calculation setting for that field and use this merge tag there. Then in your notifications and confirmations you could use the field merge tag for the Number field: something like: {My Subtotal Number Field:9}. Does that make sense?

  125. bluantinoo
    bluantinoo May 29, 2013 at 4:47 am

    David I see your example, but how to let users insert a coupon code that apply that subtotal calculation formula?

    Reply
    1. bluantinoo
      bluantinoo May 31, 2013 at 10:42 am

      I’ve figured out, Quite easy actually:

      1) “PROMO CODE” FIELD: you make a text field where users can write a coupon code.

      2) “DISCOUNT” FIELD: you make a new product field for each discount you want to apply, setting file type as “calculation” and then using the {subtotal} merge tag to build a formula.

      Example: formula for a 10% discount: {subtotal} – ( {subtotal} * 0.1 )

      3) HOW TO APPLY DISCOUNT: just edit advanced properties of this “DISCOUNT” field and activate the Conditional Logic based on the value of the “PROMO CODE” field. I mean: you show the discount field only if a users enters a specific coupon code.

      If you want to apply more than a promo code, just make several “discount” fields with different formulas and conditional logics for different codes

      Really nice David! :)

    2. bluantinoo
      bluantinoo May 31, 2013 at 10:49 am

      ops! copy/paste error: the correct formula for 10% is what David shows in the screenshot: – ( {subtotal} * 0.1 )

  126. Ron
    Ron April 29, 2013 at 4:08 pm

    I’ve been looking for an easy way (is there such a thing…) to add a simple merge tag. This would be Site Name – the name of the multisite. {site_name}

    I know that getting the site name is easy part:

    //get MU site name global $blog_id; $local_site_name = get_blog_details( array( ‘blog_id’ => $blog_id ) );

    I’m going to look at your code for adding a Merge tag but it may be a bit beyond me. There’s a lot more going on there than I need. Any pointers would be appreciated!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.