Skip Navigation

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.

WordPress 6.7 has introduced a new issue that impact translations, please update WooCommerce and WPML to the latest versions before you report issues. More about this here - https://wpml.org/errata/php-error-wp-6-7-notice-function-_load_textdomain_just_in_time-was-called/
Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 -
- 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 -

Supporter timezone: Europe/Madrid (GMT+01:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by michalN-11 1 year, 4 months ago.

Assisted by: Nigel.

Author Posts
July 3, 2023 at 9:48 am #13931483

michalN-11

Problem with rounding on 2 decimal on frontpage. pict1 ju see the price 10,92€, on pict2 is set to see 3 decimal and the price is 10,926€. Correct rounding on 2 decimal will be 10,93€. I have Slovak comparator Heureka and this plugin give me price (€) from wpml:

<PRODUCT>
<![CDATA[ Zámečnické kladivo, 800 g ]]>
</PRODUCT>
<PRICE_VAT>10.93</PRICE_VAT>

As you see rounding is correct. But admins from heureka don't want to start my eshop, because the price must be on 2 decimal correct inside the feed and on the frontpage.

Can you help me? Primary language is Czech (CZK) and the seccond is Slovak (€).

pict2.jpg
pict1.jpg
July 3, 2023 at 1:58 pm #13933579

Nigel
Supporter

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

Hi there

What do you have set for the rounding settings for that currency?

Go to the Multicurrency tab of WooCommerce > WooCommerce Multilingual & Multicurrency, and you should be able to see settings for rounding, as in the screenshot.

Screenshot 2023-07-03 at 14.56.48.png
July 3, 2023 at 2:05 pm #13933661

michalN-11

Rounding is set to 2 decimals, but the price 10,926 rounded to 10,92 and that is incorrect. The correct rounding is 10,93.

July 3, 2023 at 3:07 pm #13934575

Nigel
Supporter

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

Can you show me a screenshot of the settings?

Rounding has the option to round up or to round down, or nearest.

July 3, 2023 at 3:16 pm #13934667

michalN-11

Rounding to the nearest integer is disabled. When is enabled (picture 3) the from price 10,926 is 11,00€. But I must have 10,93

3.jpg
July 3, 2023 at 3:45 pm #13934997

Nigel
Supporter

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

Sorry, you are right, those settings only apply when rounding to an integer.

When working with decimals, there are no rounding options available, and—in testing—I can confirm that the converted price is always rounded down.

I'm checking with my colleagues to see if there is some other means (e.g. a code filter) to affect the rounding, and I'll get back to you.

July 4, 2023 at 8:37 am #13938129

Nigel
Supporter

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

I can see in our codebase that we use floor rather than round to calculate the price to the specified number of decimal places in secondary currencies. (I'm not sure why, I suspect it was a simplification relating to older versions of PHP.)

It's not something that can be adjusted via filter, until this is fixed in the plugin if you want it to round to the nearest decimal you will need to make a small change to the plugin files.

You will need to edit the file plugins/woocommerce-multilingual/inc/currencies/class-wcml-multi-currency-prices.php.

Locate these lines (around line 481):

			// Use configured number of decimals.
			$price = floor( $price * pow( 10, $currency_options['num_decimals'] ) + 0.0001 ) / pow( 10, $currency_options['num_decimals'] );

and replace that with

			// Use configured number of decimals.
			$price = round( $price, $currency_options['num_decimals'] );

I'll leave this thread as escalated and when I get notice that the issue is fixed I'll let you know.

July 4, 2023 at 12:49 pm #13941299

michalN-11

After replaced code, rounding on 2 decimal si correct. Thank you very much..