Skip Navigation

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.

This topic contains 0 replies, has 0 voices.

Last updated by piaP-6 2 weeks ago.

Assisted by: Dražen Duvnjak.

Author Posts
November 12, 2024 at 8:03 am #16391201

piaP-6

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?

November 12, 2024 at 9:29 am #16391723

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

I have escalated to our 2nd tier, they will check and advise further or escalate to developers.

I will update you when I have more news.

Regards,
Drazen

November 12, 2024 at 9:56 am #16391883

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

our 2nd tier checked and seems the issue reported is fixed by applying the next option:

- Enable "Round tax at subtotal level, instead of rounding per line" in WooCommerce > Settings > Tax > Tax Options screen.

- hidden link

Regards,
Drazen

November 14, 2024 at 10:48 am #16401763

piaP-6

Hi Drazen,

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){

$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) + round($tax_amount, 2);

return $eur_price_with_tax . ' ' . $currency;

}