Skip Navigation

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

Problem:
The client reported that the currency switcher was not being respected when using the 'cookie' storage strategy. Despite changing the currency on the EN site, it always reverted to 'GBP'. The client had already disabled server caching and set the 'default customer location' to 'No location by default'. The issue persisted even after applying a filter to use cookie storage.

Solution:
We advised the client to replicate the issue on a sandbox site and provided instructions for doing so. The client discovered that the problem was caused by adding the store strategy filter too late in the execution order, specifically during the 'init' action. The client resolved the issue by changing the action to 'plugins_loaded', which allowed the cookie value to be respected.

If you're experiencing a similar issue, we recommend you try changing the action hook to 'plugins_loaded' when adding your store strategy filter:

add_filter( 'wcml_user_store_strategy', function( $strategy, $key ) {<br />    return 'cookie';<br />}, 10, 2 );

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. 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 2 replies, has 2 voices.

Last updated by willR-4 1 year, 1 month ago.

Assisted by: Osama Mersal.

Author Posts
March 23, 2024 at 9:42 am #15442963

willR-4

This is a follow-up to this ticket: https://wpml.org/forums/topic/split-currency-switchers-location-feature-not-always-working-as-expected/

First, I have completely disabled the server cache on the site to rule out any issue with caching.

With the default strategy 'session', the currency switcher works fine. That is, it keeps the value after changing.

But if I change the 'store strategy' via a filter to 'cookie', then the currency switcher isn't respected at all. For example, on the EN site, currency is always 'GBP', despite having changed to 'EUR'. See screen shot showing the currency switcher 'GBP' with the cookie 'wcml_client_currency' set to 'EUR'.

I changed the 'default customer location' to 'No location by default' to rule out any geolocation issues. Settings for Currencies are 'Show currencies based on' = 'Site Language' (see screen shot for other values).

Why isn't the currency switcher respected when using the storage strategy 'cookie'?

Note that you still have admin access from the previous ticket.

Screenshot 2024-03-23 at 10.38.02.png
Screenshot 2024-03-23 at 10.32.29.png
March 25, 2024 at 4:01 pm #15447818

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

Thanks for contacting WPML forums support. I'll be glad to help you today.

First of all, sorry for the late reply; it was due to a higher workload. Please log in to this sandbox site and replicate the issue. (hidden link)

If the issue is replicable, please let me know how to reproduce it so that I can consult our second-tier support team about it.

Thanks for your cooperation and patience.

Best regards,
Osama

March 26, 2024 at 9:07 am #15450146

willR-4

Hi - I can recreate the problem on the sandbox site with my parent theme installed. I also copied all the settings from my site. I also add the filter to use cookie storage to the theme functions file:

add_filter( 'wcml_user_store_strategy', function( $strategy, $key ) {
return 'cookie';
}, 10, 2 );

To re-create the bug:

Start in EN store (currency is GBP).
Switch to French store (currency automatically switches to EUR).
Change currency to GBP.
Go to a different page (product or category).
=> Currency has switched back to EUR.

Note this happens with the settings in the screen shot. Specifically, Multicurrency settings page (hidden link), 'Show currencies based on' = 'Site language' and 'Currency displayed first' = 'GBP for 'EN', 'EUR' for 'FR'.

Note that if I change these to 'Keep', then the currency stays selected.

I was unable to reproduce with the Storefront theme, and it happens when I use either the parent theme 'Modules' or the child theme.

Screenshot 2024-03-26 at 09.47.41.png
March 26, 2024 at 11:50 am #15450952

willR-4

I did some more debugging on my server and found the problem. I was adding the store strategy filter in an mu-plugin via the 'init' action. This was too late for the cookie to be applied. Instead, I changed the action to 'plugins_loaded' and now the cookie value is respected.