Skip to content
Advertisement

Subtract tax from a price with tax in OpenCart?

How do I subtract all taxes from a price with tax in OpenCart?

In the example below I use the default “Taxable goods” tax setting from OpenCart, which is 20% VAT + $2,00 Eco-Tax.

JavaScript

This returns an incorrect value of $14,64 because it calculates the tax on $number (20,80), which already is a price with tax. The correct price for $20,80 without tax should be $15,67

This should be the formula in this case: (20.80 – 2.00) / 120 * 100 = 15.6667

Is there any way to subtract all taxes from a price that already has tax included?

Advertisement

Answer

JavaScript

RESULT with 20% tax

JavaScript

RESULT with 15% tax

JavaScript

Try a few dry runs and then check with this code

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement