How do I subtract the tax from a price with tax?
Customers in my project should be able to enter a price without worrying about taxes, so I need to subtract the tax from it before storing it into a database.
In the example below I use OpenCarts default "Taxable goods" setting: 20% VAT + $2,00 Eco-Tax .
Code: Select all
$number = 20.80
// Get $number tax:
$tax = $this->tax->getTax( $number , $product_info['tax_class_id'] , $this->config->get('config_tax') );
// Subtract tax from total price:
$result = $this->currency->format( ( $number - $tax ) , $this->session->data['currency'] );
The calculation should be:
(20.80 - 2.00) / 120 * 100 = 15.6667
OpenCart 3.0.3.8 (Default)