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!
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.
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.
Hi Christopher,
Can you please try this updated version of the snippet and see if it helps?
https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-calc-subtotal.php
Best,
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
Hi Mary,
Thanks for writing in. From what I understand this should be possible with Gravity Forms eCommerce Fields perk. Another option would be using this other snippet: https://gravitywiz.com/gravity-forms-progress-meter/.
Best,
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
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,
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
Total: 95$ per month
Any ideas how I can achieve this?
Thanks for your help.
Hey Robby, To ensure that all calculations go through properly, your best bet may be the dedicated Gravity Forms eCommerce Fields perk we offer. All of the calculations can be handled with Gravity Forms Product plus options. Then to ensure the correct fields show you can use conditional logic. IF you have a Gravity Perks License we would be more than happy to take a look at the form. Just drop us a line through our support page. π
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 ) {
<
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?
Hello Alissa, this is a bit of a strange one. Have you tried running a conflict test or ran some Snippet Troubleshooting to make sure nothing else was interfering with the code? IF you have a Gravity Wiz license we could take a closer look into this for you. You could reach out to us through our support page found here.
Does this plugin include calculating flat rate tax, for total purchase on the site?
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.
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!
Hello Sarah, how are you calculating the tax field currently? Let us know. π
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/
Hello Sarah, Sadly the subtotal field will take in all products. The only way around this would be to get the Gravity Forms eCommerce Fields perk. This will allow you to add a tax field as well as exclude products from the tax field.
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!
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!
Thanks for the fast replay. Yes, I’m using number field to calculate tax and show total on some products. Can’t give url at the moment but heres a screen: http://tiny.cc/5ukymz
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? π
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.
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. :)
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.
never mind. It was a formula error. Thanks for always being so awesome. Love you’re site and your code snippets.
Hello Dave,
Happy that you were able to get the calculation on your total form to work. Have a great day! :)
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
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.
You are great person, Thank you so much
β€οΈ
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]
Fixed!
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/
[…] 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 […]
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?
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.
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?
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.
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?
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.
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.
More than likely a form you are referencing no longer exists.
We recommend using the plugin version, Gravity Forms eCommerce Fields, which includes support if you’re still having issues.
“Download Plugin” not working?
Fixed. ?
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!
Hm, I’m not sure I understand? Is this caused by the {subtotal} merge tag?
My apologies. I needed to upgrade Stripe Add-On from 2.5 to 2.5.4. That fixed my issue. Thank you for responding.
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.
Depending on the complexity of your needs, this plugin might be a much cheaper option than hiring a developer: https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
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!
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.
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?
Hi Scott, I’ve added a proper plugin header to the snippet.
Thanks, David!
THANK YOU!!!
My pleasure, Jocelyn. ?
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
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
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!
Hello all, this has been fixed. Grab the latest version of the snippet above.
Thank you David! confirmed working. I appreciate it, have a nice weekend.
Thanks very much David for the speedy update. Much appreciated!
Glad to help! ?
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.
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.
I believe that this snippet stopped working with the release of the new 2.4 version.
Fixed. Latest version above. :)
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.
Disregard my last comment. sorry i figured it out!
Thanks for this. I used this solution to allow me to use the subtotal in a conditional statement for another field. Very helpful.
Glad it helped you!
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
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?
Hi Ronny, we don’t have a solution for this one.
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!
Hard to say, Janice. If you’re a Gravity Perks customer, we’ll be happy to dig in via the support form.
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?
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.
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.
Add a negative sign in front of of your formula.
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.
Aha!
I added another set of parenthesis around the whole thing and now it’s calculating properly!
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!
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.
[…] Forms Add Subtotal Merge Tag (This is an INN fork of Subtotal Merge TagΒ and must be installed […]
[…] Subtotal Merge Tag (for Calculations) via GravityWiz.com […]
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
I’d give GF eCommerce Fields a try. It supports a much improved method for calculating the subtotal.
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 :-(Hi Chris, this snippet is limited to the formula setting of a calculation-enabled fields. If you’d like a more flexible (and powerful) version, check out GP Ecommerce Fields.
[…] Forms Add Subtotal Merge Tag (This is an INN fork of Subtotal Merge TagΒ and must be installed […]
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?
Hi Maggie, what are the actual contents of that line on your end?
On my end, line 446 is this: mergeTags[“pricing”].tags.push({ tag: ”, label: ” });
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
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).
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?
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. :)
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
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.
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.
My pleasure, Mische. Glad you were able to get this working. :)
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
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.
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
Hi Mische, we do not currently have a solution for this one. Leaving this open for any other users who might have a suggestion.
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.
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.
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!
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?
We are using Gravity Forms PayPal Standard Add-On. The plugin is update but still unable to redirect to paypal checkout page.
We’d recommend picking up a copy of Gravity Perks and dropping us a request for GP Subtotal & Tax. If it doesn’t work with the plugin-version, we’ll be happy to provide support.
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?
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.
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
This might help, Eddie: https://gravitywiz.com/documentation/snippet-troubleshooting/
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!
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?
Hi Todd, GP Subtotal & Tax provides support for a Tax field that will automatically exclude the discounted amount from the calculated tax. This perk is available to Gravity Perks license holders by request.
This was a great help. Thank you so much!
Glad to hear it, John!
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!
Awesome, glad you were able to make this work for you. :)
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.
Could you send me an export of your form?
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.
Hi Simon, GP Subtotal & Tax provides support for a Tax field that will automatically exclude the discounted amount from the calculated tax. This perk is available to Gravity Perks license holders by request.
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
Do you have a URL where I could view your form?
Finally i replaced the {subtotal}. Maybe in a future i will use this snippet. Thanks.
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.
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
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.
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?
Hm, we’re not able to recreate this issue. Feel free to send us an export of your form.
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
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
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.
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
You can apply the {subtotal} to the form total by included it in a Calculated Product field rather than a Number field.
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.
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.
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.
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.
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
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
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!
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!
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() ); }
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!
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() ) } );
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!!!
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
Hi Daniel, pick up a copy of Gravity Perks and request a copy of GP Subtotal & Tax via the support form. It’ll handle calculating taxes much better than this snippet.
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.
Pick up a copy of Gravity Perks and send me a request for GP Subtotal & Tax via the support form. It will allow you to calculate a tax and also exclude specific products from that tax.
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,
What type of product is it? The value modifier is only applicable to choice-based products which support the value property on each choice.
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?
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 :-)
Ah, perfect. Glad you were able to get this figured out. :)
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
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.
I’ve updated it to floatval( $qty_value ) from intval( $qty_value ). That should work for you too, I think. :)
This code works for me too. Thanks a lot !
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?
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.
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?
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?
Hm, do you have a URL where I could view your form?
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
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
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.
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!
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
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.
Hi David – really loving the perks! I installed this snippet on my theme function at http://www.thecompletehomewarranty.com/enroll-home-buyer/
The subtotal works… but everything runs really slow…. like incredibly slow? Any thoughts on how to speed this up. I have cleared my cache, history etc. I watched the snippet video. Thanks David!
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?
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!
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.
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.
Hi Prayas, can you send me an export of your form and more details on how you are prepopulating your form?
Is there any update on making this work with the Gravity Forms Coupon add-on?
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.
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!
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.
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;}
Hi Nykke, this code does not add any styles to the markup and the only modifications it makes to the form object is to the calculationFormula setting. The only thing I can think of is perhaps the snippet was not installed correctly. Take a look at this help doc and let me know how it goes: https://gravitywiz.com/documentation/snippet-troubleshooting/
I tried install the code in function.php but got a syntax error. Any update to this code or including in a perk?
https://gravitywiz.com/documentation/snippet-troubleshooting/
Hey David, this has been extremely helpful! I am running into one issue where the last two fields of my form won’t populate in the email notification.
http://cpprofessional.staging.wpengine.com/services/office-space-calculator/
The fields that aren’t going to the notification are Add On Factor and Total Rentable Square Feet.
I’m hoping you might have an idea of what I did wrong.
Thanks! Brian
When you view the entry in the backend, do these fields have values?
They don’t, they have 0’s in the two fields.
Whew!!
Thank you so much for this! would not be able to do this myself
Glad to help, Matt. :)
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?
Hi Travis, it looks like you’re experiencing the same issue as Andre. See my answer to him here: https://gravitywiz.com/subtotal-merge-tag-for-calculations/comment-page-3/#comment-225292
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/
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.
David, thanks for your reply. The form is not particularly big and there are somewhere around 10 fields that amount for the total and only a couple involved in the actual calculation.
You can grab the export from that URL:
http://dev.ecovoile.com/gravityforms-export-2015-07-16.json
Thanks again for your help!
Hi David, I sent you a reply with the link to the export. Have you got it?
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.
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!
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!
Awesome! Just send the beta over. :)
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
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
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.
Hi Paul, are you using a Calculated Product field with the Subtotal rather than a Number field?
I’m using the number field sir. Should i use the product field?
Yep. Number fields are not calculated towards the total.
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….
Nope, should work. Do you have a URL where I could view your form?
thx for the quick answer: http://webshop.printmediagroup.eu/product/affiches/
Is this your Calculated Product which uses the {subtotal} merge tag? http://grab.by/IhD6
HI David,
As you can see on this link, it doesn’t add to the total peice… what to do?
http://webshop.printmediagroup.eu/product/affiches/
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))
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…
I’m not sure what the issue could be, Sven. I checked the demo (running the latest version of Gravity Forms) and it’s working as expected. I would try a theme/plugin conflict test.
https://www.gravityhelp.com/documentation/article/testing-for-a-themeplugin-conflict/
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 ;) )
Ah, I see. Glad you got this sorted. :)
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
Hi Alex, this is probably possible with the GF Survey Add-on.
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
Hi Thierry, I’m not able to recreate this issue. If you remove just the
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
Just used this for a form where I needed to calculate a 10% discount for members. Worked perfectly! Thanks heaps!
Awesome! Glad you were able to find a good use for this. :)
Hello David,
Is there a snippet to support radio or check boxes. They are supported in Calculations as of 1.9?
Thanks
I’m not sure I understand your request?
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?
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.
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??
Hi Oscar, another developer wrote a snippet for this here: https://gist.github.com/richardW8k/8717834
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?
I’m not sure off the bat. If you’d like to commission me to figure this out for you, please do get in touch.
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.
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.
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.
Glad to help, Andy.
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
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.
Or use a child theme
Thanks for an awesome snipped .
You saved me a ton of time :)
Worked perfectly
Glad to help, Ayush. :)
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.
Hi Nadeem, I’ve replied via email requesting additional access.
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
Hi Ann Marie, see if this troubleshooting doc helps: https://gravitywiz.com/documentation/snippet-troubleshooting/
Tried to copy this in and received a syntax error so took it back out.
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
Damn, it didn’t work when I copied the code in my themes functions.php file
Are you seeing any errors? Do you see the Subtotal option in your Calculation drop down?
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
Try removing the entire contents of your theme’s functions.php (assuming this is where you installed it). I’m betting some code got left behind that may be causing issues. As far as reinstalling the snippet, see here:
https://gravitywiz.com/documentation/snippet-troubleshooting/
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
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.
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?
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.
I tried this twice at the bottom of function.php, one with the leading <?php, and again without, both time the site goes white?
Hi Mike, make sure you’re adding this to your theme’s functions.php and not the wp-includes/functions.php.
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
Ah, perfect. Glad you got this working. You can sign up for updates in the sidebar. :)
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
Hi Dolmat, the current version of this does not support this feature; however, an upcoming perk-version will.
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!
Hi David,
I found the email and just replied! Thank you!
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
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
Hey LV, I replied to your email with some more info and also requesting more info. :)
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
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.
I copied the code and placed at the bottom of my theme functions file. The subtotal is not showing up in the insert merge tag. http://kreweoftitans.com/?page_id=205
Trying to make 50% of the order due and required to pay if they do not pay in full.
Hi Darren, you get this figured out? Your form appears to be functioning as expected.
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
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.
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
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?
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)?
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!
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}
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.
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.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?
Hi Robert, did you try my suggested approach first? If not, give it a try and confirm.
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?
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.
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!
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
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
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?
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! :)
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:
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!
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. :)
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?
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?
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]
Hi David, Did you get a chance to look at my form? Thanks so much for your help! -Kristen
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
Awesome usage example, Stuart. Thanks for sharing!
Does this still work? When I paste the code into my functions.php it breaks my site. (everything is white.)
Hi Taylor, try removing the opening <?php tag (from the snippet) and make sure you’re running the latest version of Gravity Forms.
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.
Hey Ed, glad to help!
Hi David,
Your demo doesn’t seem to be working as of today…
Hi Paul, I’ve updated the code to resolve this issue. The demo should work correctly now. Thanks for letting me know. :)
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.
My pleasure. Glad you found it useful. :)
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
Hi Sven, do you have a form where I could see this error live?
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?
never mind I found problem Thank you very much it is life saver
Awesome! Glad you were able to get this working.
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 :/
Can you provide a URL to a form where I can see this issue?
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?
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.
Could you clarify what you mean here? I’m not sure I follow.
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!!
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.
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 :)
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.
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
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. :)
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.
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
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. :)
Thanks for the great snippet. Unfortunately it does not appear to be working on GF 1.7.12
Thanks for the heads up. I will take a look as soon as I can.
Version: 1.7.12
Having the same problem of the “Subtotal” merge tag not being available from the select menu.
Still can’t see the “subtotal” field in the “Insert Merge Tag” dropdown.
Any ideas?
Thanks for the heads up. I will take a look as soon as I can.
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?
Hi Ryan, what version of Gravity Forms are you running?
Any way to modify this to sum the total of values in a column of a list field? (http://wordpress.stackexchange.com/questions/119691/gravity-forms-sum-list-fields)
[…] anyone know how to sum a list field? Gravity wiz offers a solution on how to create a merge tag (https://gravitywiz.com/subtotal-merge-tag-for-calculations/). Say I have form 21 and field 42 which is a three column list field. I want to sum the total of […]
Hi David, I tried applying the above to my form but I couldn’t get it to work, as it just displays zero.
It’s at the bottom of the page at https://keyangel.co.uk/residential/
Any suggestions?
Thanks Brian.
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.
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
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
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? :)
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? :)
Sorted, was a silly mistake by myself leaving a gap before the first <?php tag, thanks David for the quick contact!
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
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
[…] 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 […]
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?
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?
I’m having the same issue. Otherwise this is a very helpful hack
David, thank you for taking care of the issue with the latest patch!
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?
i try to use it but it return me an higher value, i dont understand why, i use it in a calculation product field
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.
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?
Beautiful! This just saved me a tonne of headaches. Thank you!
That’s great yes, it works fine!
David this is great, thank you. One thing i cant do is add the merge tag in confirmations or notifications. Is that not possible?
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?
David I see your example, but how to let users insert a coupon code that apply that subtotal calculation formula?
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! :)
ops! copy/paste error: the correct formula for 10% is what David shows in the screenshot: β ( {subtotal} * 0.1 )
Would it be possible to use this subtotal snippet to create some kind of coupon discounts?
Sure. Example: http://grab.by/mYHM
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!
Thanks for sharing the Snippet ,
its very helpful,
My pleasure! Glad you found it useful. :)