Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client reported an issue with WPML multicurrency where, after a sale ends, the product price does not revert to the original price correctly. This problem occurs when the sale end date is reached, and the sale price fields become empty as expected, but the original price displayed is incorrect, seemingly due to a currency calculation error.
The issue is related to the price filter on scheduled event when the default currency is not set for the default language.

Solution:
We provided a workaround to address the issue until a permanent fix is released in a new version of WooCommerce Multilingual (WCML). We recommended adding the following code to the functions.php file of the client's current theme:

/**
 * @link wpmlsupp-11119
 */
function wpmlsupp_11119_remove_price_filter() {
	global $woocommerce_wpml;
	$actions_to_remove_back = [
		'wc_before_products_starting_sales' => 'wc_after_products_starting_sales',
		'wc_before_products_ending_sales' => 'wc_after_products_ending_sales',
	];

	if ($woocommerce_wpml instanceof woocommerce_wpml && isset($actions_to_remove_back[current_action()])) {
		remove_filter('get_post_metadata', [$woocommerce_wpml->multi_currency->prices, 'product_price_filter'], 10);
		add_action($actions_to_remove_back[current_action()], function () use ($woocommerce_wpml) {
			add_filter('get_post_metadata', [$woocommerce_wpml->multi_currency->prices, 'product_price_filter'], 10, 4);
		});
	}
}
add_action('wc_before_products_starting_sales', 'wpmlsupp_11119_remove_price_filter');
add_action('wc_before_products_ending_sales', 'wpmlsupp_11119_remove_price_filter');

We asked the client to let us know if this solution resolved the issue.

Please note that this solution might be outdated or not applicable to your case. If you're experiencing a similar issue and the provided solution does not help, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket with us.

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 24 replies, has 4 voices.

Last updated by Nicolas V. 1 year, 3 months ago.

Assisted by: Nicolas V..

Author Posts
April 11, 2024 at 5:11 pm #15510590

jesperA

Hi,
It may be of course be related to the schedule feature of WooCommerce, I just assumed that worked since it really is a basic functionality. Anyway, it will be interesting to read about your results from the other sandboxes and to know where the problem lies!

April 11, 2024 at 10:13 pm #15511011

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Jesper,

I realized that our sandbox sites have DISABLE_WP_CRON by default. So it might have affected my test from yesterday.

I asked our system admin to remove this on all 3 sites and I re-ran the test on hidden link

We'll see tomorrow the results. Thanks for reporting this!

April 12, 2024 at 7:27 am #15511545

jesperA

Hi,
Well that explains why nothing was changed. Today I see the correct sale price on the second product. Looks correct.
However, please notice the wrong price on the original product. It's out of the sale and should have the original price but it's not. It's not the previous sle price either. It's a very very low pice shown in the frontend/shop but not when checking the product in the back end.

So this is exactly the problem I was reporting and it has to do that the original product have an ended sale but not returning to the correct price.

You will probably see this behaviour on the second product as well when the sale is expired.

April 12, 2024 at 3:25 pm #15513405

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Jesper,

Yes, there is definitively an issue and it's not related to the schedule feature as my control sandbox is showing correct prices.

Prices are also incorrect on the third sandbox with the latest versions on our plugins. I have escalated the issue to the second tier support and will get back to you when I have some feedback.

April 12, 2024 at 3:49 pm #15513495

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi again,

Looking at the results on the third sandbox I created with simple prices and exchange rates I could understand the issue!

It seems that the exchange rate is applied to the main currency kr for the price calculation and then re-applied to get the second currency price.

So in my case:
- Exchange rate: 2
- Regular price: 1000kr // $2000
- Sale price: 500kr // $1000

Whenever the cron (schedule) changes prices, the exchange rate is applied to KR
So regular price becomes: 2000kr // $4000 and sale price 1000kr // $1000

I think this issue occurs in the very specific case where your primary currency KR is not used in your main language. But I'll wait for the dev team feedback.

April 15, 2024 at 2:15 pm #15520680

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

I was right the issue is the price filter on scheduled event when the default currency is not set for the default language.

Here is a workaround until it gets fixed in a new version of WCML (I don't have an ETA yet).

- Add this to the functions.php file of your current theme:

/**
 * @link wpmlsupp-11119
 */
function wpmlsupp_11119_remove_price_filter() {
	global $woocommerce_wpml;
	$actions_to_remove_back = [
		'wc_before_products_starting_sales' => 'wc_after_products_starting_sales',
		'wc_before_products_ending_sales' => 'wc_after_products_ending_sales',
	];

	if ($woocommerce_wpml instanceof woocommerce_wpml && isset($actions_to_remove_back[current_action()])) {
		remove_filter('get_post_metadata', [$woocommerce_wpml->multi_currency->prices, 'product_price_filter'], 10);
		add_action($actions_to_remove_back[current_action()], function () use ($woocommerce_wpml) {
			add_filter('get_post_metadata', [$woocommerce_wpml->multi_currency->prices, 'product_price_filter'], 10, 4);
		});
	}
}
add_action('wc_before_products_starting_sales', 'wpmlsupp_11119_remove_price_filter');
add_action('wc_before_products_ending_sales', 'wpmlsupp_11119_remove_price_filter');

Please let me know if it fixes your issue.

April 15, 2024 at 3:19 pm #15521104

jesperA

Thanks, I will try the workaround. Will take a couple of days before I know if it worked.

April 15, 2024 at 8:28 pm #15521886

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi,

I'll let this ticket open and waiting for your confirmation.

Once again, thanks for reporting this issue and helping us to improve our product!

April 18, 2024 at 3:00 pm #15539839

jesperA

I was testing the workaround today (when the sale ended) and it seems to be working.
So I think you found the problem!
Thanks for the work researching this problem. Will the workaround be included in the next update?

April 18, 2024 at 5:59 pm #15540528

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Bonjour,

Le ticket interne a été assigné à la version WCML 5.5.0. Donc ce ne sera pas dans la toute prochaine version (puisque nous sommes a 5.3.6) mais un peu plus tard je pense.

Malheureusement je ne peux pas vous donner de date (ETA) pour le moment.

Vous pouvez consulter le changelog ici: https://wpml.org/download/woocommerce-multilingual-multicurrency/?section=changelog