• We have a product which costs:

    14,29 excl. VAT
    17,00 incl. VAT (19%)

    We enter the prices excl. VAT. Now, if we put that product with an amount of 2 into the cart, the total price of these two products is calculated 34,01 incl. VAT, which is wrong. It should be 34,00.

    WooCommerce seems to add the VAT on each product and then sum those values. Instead, it should sum the values excl. VAT and then add the VAT.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    14.29 x 2 = 28.58
    28.58 x .19 = 5.4302

    28.58 (product costs) + 5.4302 (tax) = 34.0102.

    If you round the tax to two digits and the final number to two digits, you still get 34.01.

    WooCommerce seems to add the VAT on each product and then sum those values. Instead, it should sum the values excl. VAT and then add the VAT.

    I just summed the values excl. VAT and then added the VAT above.

    Thread Starter scheichmanfred

    (@scheichmanfred)

    Agree, my mistake.

    So it should round each products price incl. VAT and then add up the values.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Thread Starter scheichmanfred

    (@scheichmanfred)

    This does not answer the question. Still:

    14.29 * 1.19 = 17.0051
    => *2 = 34.01

    But the price should be 34.00, because it should be rounded for each item.

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    I don’t want to sound rude, but it seems like you just don’t like how it works because it isn’t coming out to an even number on your site.

    Your first said it should work like this:

    it should sum the values excl. VAT and then add the VAT.

    Which is correct, and how it does work. The doc Mike linked to explains how taxes work, and I worked the math out above for you.

    I’ve read through this thread and also the https://github.com/woothemes/woocommerce/wiki/How-Taxes-Work-in-WooCommerce Wiki entry. And it makes perfectly sense to me.

    However, this issue is not about tax calculation but about when to round. And I have to admit that @scheichmanfred is right.

    Let’s assume I have a shop that has stored all the product prices incl. taxes.
    Furthermore, let’s assume I display the prices without taxes on all pages and also in the checkout process.

    Now this works fine for single items. But whenever I add more than one of a kind to the cart, we might get a problem, because prices are not rounded at the time they are supposed be.

    Let’s imagine the following situation:

    Product #1
    Stored price incl. tax: 25,00
    Tax rate: 20% (=0.2)
    Calculated price excl. tax: 20,83 (=25/1,2=20,833333333)
    Displayed single unit price: 20,83

    Everything fine so far, right?

    But now let’s look at the calculation when we add multiple units to a cart.

    4 x Product #1
    Expected total price excl. tax: 83,32 (=4*20,83)
    Displayed total price in cart excl. tax: 83,33 (=4*20,83333333333)

    The cart now shows the single unit price correctly as rounded 20,83.
    But the total price will be shown as 83,33, which is not correct in this context, since the rounded single unit price is indeed 20,83 and not 20,83333333333.

    As a result, the cart will always display a wrong amount for multi unit items, since rounding doesn’t take place before multiplying the single price.

    So, to correct this situation, we could either show the single price the calculation is based on (20,83333333333) or we could simply round the single unit price before multiplying it by the number of units.

    Do you still think this is not a problem @icaleb?

    Let me know if my thoughts are not correct and there already is a way to fix this issue.

    Any news on this @mikejolley or @icaleb? ??

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Current implementation adds up the values to 4dp but the displayed 2dp numbers, so throwing maths at us won’t change this :p Rounding will break discounts split over multiple products.

    I suggest you contribute to https://github.com/woocommerce/woocommerce/pull/14475. This does have implications (negative ones IMO) for discounts.

    Thanks for your reply! ??

    Sorry, I was just trying to illustrate what I see is going on, no intention on throwing maths at you ??

    Well, I’ll have a look at the PR, but I guess without a good understanding of the WooCommerce codebase I’ll only be able to contribute in describing how it should work, but not be able to implement the change right away.

    Will follow up here, once some kind of solution came up.

    did you came up with any solutions to this, because I have exactly the same problem…

    Unfortunately I haven’t. In theory it seems easy to do it right, but as we can see from the Pull Request there seem to be problems with discounts, once the issue we experience is fixed.

    I guess it shouldn’t be too hard to apply a consistent rounding model in WooCommerce, but I have no motivation or time to look into this right now, sorry! ??

    I’m a bit surprised though that this issue didn’t come up earlier and isn’t reported by more people. From my quick experiments a way to mitigate the effects of this a bit, could be to add prices to products excluding taxes and let WooCommerce do all the tax calculations.

    In my opinion, the first price on the page that is calculated from a price in the database and a tax rate, should be rounded to 2 digits precision. From there all prices on the page that refer to this price (e.g. multiple items prices, discounted prices) should be calculated from this rounded value. This would be the consistent way a user would expect it to work and also how it would work in a real life shop.

    thanx. Actually I’m entering prices without tax allready, but when woo applies tax it automatically calculates it using 4 digits, which is the root of all problems ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Wrong calculating cart amount’ is closed to new replies.