This thread is resolved. Here is a description of the problem and solution.
Problem: The client is experiencing rounding errors when converting product prices from Danish Krone (DKK) to Euro (EUR) with German tax on their WooCommerce site. The custom function used for conversion does not round the prices correctly, leading to discrepancies in the displayed prices. Solution: We recommend enabling "Round tax at subtotal level, instead of rounding per line" in WooCommerce > Settings > Tax > Tax Options screen for a potential alternative solution.
If this solution does not resolve your issue or seems outdated, please check the related known issues and confirm that you have installed the latest versions of themes and plugins. If the problem persists, we highly recommend opening a new support ticket for further assistance.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Background of the issue:
I am trying to convert product prices from the default currency with Danish tax to Euro with German tax on my site hidden link. I am using a function to calculate the price in Euro, which involves applying filters and calculating taxes. The function is as follows: function get_price_by_currency($price, $currency){ if ($currency == 'DKK'){ return $price . ' ' . $currency; } elseif ($currency == 'EUR'){ $eur_price = apply_filters('wcml_raw_price_amount', $price, $currency); $eur_price_ex_tax = $eur_price / 1.25; $tax_rates = WC_Tax::find_rates(array( 'country' => 'DE' )); $taxes = WC_Tax::calc_tax($eur_price_ex_tax, $tax_rates, false); $tax_amount = array_sum($taxes); $eur_price_with_tax = round($eur_price_ex_tax, 2) + $tax_amount; return $eur_price_with_tax . ' ' . $currency; } else{ return apply_filters('wcml_raw_price_amount', $price, $currency) . ' ' . $currency; } }
Symptoms:
There are rounding errors in the price conversion. For example, I get 9.73896, but it shows as 9.73 on the website when calculated by the default plugin.
Questions:
How can I fix the rounding errors when converting prices to Euro with German tax?
Thanks for checking up on that. Instead of changing that option, I have changed my custom function to do the rounding before summing the tax with the price excluding tax. That seems to do the same.
function get_price_by_currency($price, $currency){