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.

This topic contains 74 replies, has 3 voices.

Last updated by Sumit 7 months, 4 weeks ago.

Assisted by: Sumit.

Author Posts
February 22, 2024 at 11:29 am #15333153

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. We are still working on this and get back to you as soon as possible. Please wait.

--
Thanks!

Bigul

February 22, 2024 at 10:59 pm #15335782

louisN-4

how long do you think that would take, we hardly get any orders from secondary languages due to the speed

February 23, 2024 at 8:33 am #15336379

Bigul
Supporter

Languages: English (English )

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

Hello,

Please add the following code in functions.php of your theme after a full site backup and make sure the issue exists or not.

// Use Cookie instead of WCSession
add_filter( 'wcml_user_store_strategy', function ( $strategy, $key ) {
    return 'cookie';
}, 10, 2 );

add_filter( 'wcml_is_cache_enabled_for_switching_currency', '__return_true' );

The wcml_user_store_strategy filter will help to create cookies, especially when using cache plugins. For more details, please refer to this article: https://wpml.org/wcml-hook/wcml_user_store_strategy/.

--
Thanks!

Bigul

February 23, 2024 at 10:03 am #15336856

louisN-4

1. that means we also have to change our ?currency related script? shows in this link?
https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/page/2/#post-15313379

2. anyway to also make the url change, because this is what litespeed wants, so when you use wcml currency switcher, it changes the url as well

February 23, 2024 at 11:14 am #15337268

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. Please comment code shared in the following thread after a site backup.

https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/page/2/#post-15313379

Then try with the following code and check if it works or not.

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

--
Thanks!

Bigul

February 23, 2024 at 11:36 am #15337335

louisN-4

1. i don't understand what you mean by saying "Please comment code"

2. it seems you don't understand but the code share with you in the link, is something we got from you:
https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/page/2/#post-15313379

and is a code given by you on this thread, to handle cases where in the URL we have ?currency=XXX

February 23, 2024 at 1:11 pm #15337748

Bigul
Supporter

Languages: English (English )

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

Hello,

Please note that code commenting is an easy way to inactive code while testing. It will help us to test without removing or deleting the code like the following - hidden link

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

As per your previous replies, we thought you were trying to create cookies for currency and change the URL with the code shared in the following thread while a user selects currency from the WCML Currency Switcher as a workaround for this bug.

https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/page/2/#post-15313379

So just to make sure, is this code shared by us in the Past? Because in this ticket we only shared the workaround suggested here.

https://wpml.org/forums/topic/follow-up-to-site-language-resetting-the-cache/page/2/#post-13035833

https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/#post-15273277

https://wpml.org/forums/topic/wpml-latest-4-6-9-litespeed-issue/page/2/#post-15295862

--
Thanks!

Bigul

February 23, 2024 at 2:42 pm #15338335

louisN-4

man you are not getting it, so let me explain again - the two issues are tied to this discussion of litespeed

we have this code so we can add ?currency=XXX to any url for example
hidden link
so the url opens with AUD currency, instead of the default currency that loads just with the url
hidden link
which is USD

now the way to make ?currency=XXX work is this code:

add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );

function modify_client_currency( $current_currency ) {
if( !is_admin() ){
global $woocommerce;

if(isset($_GET['currency']) && !isset($_COOKIE['client_currency_cookie'])){
$currency = esc_attr( $_GET['currency'] );
$currency = strtoupper( $currency );
$currencies = get_woocommerce_currencies();
if ( array_key_exists($currency, $currencies)) {
if ( ! $woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie( true );
$woocommerce->session->set( 'client_currency', $currency );
} else {
$woocommerce->session->set( 'client_currency', $currency );
}
setcookie( "client_currency_cookie", $currency, 0, '/' );
} else {
return $current_currency;
}
}else{
if(isset($_COOKIE['client_currency_cookie'])){
$currency = $_COOKIE['client_currency_cookie'];
}else{
$currency = $current_currency;
}
}
return $currency;
}
}

add_action( 'wcml_switch_currency', 'my_custom_action_kideno', 10, 1 );
function my_custom_action_kideno( $new_currency ) {
global $woocommerce;
if ( !$woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie(true);
$woocommerce->session->set('client_currency', $new_currency);
}else{
$woocommerce->session->set('client_currency', $new_currency);
}
setcookie("client_currency_cookie", $new_currency,0,'/');
}

we have 2 places where user can change currency:
1. on the top right, you have an icon and if you mousehover, it loads the currency list of that page
2. below add-to-cart button, you have a dropown

NOW litespeed said, they don't want to cache EN/NL/DE/RU probably due to the multicurrency thing

so you brought me a code to add as another snippet

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

add_filter( 'wcml_is_cache_enabled_for_switching_currency',

and then i asked you if we also need to change the ?currency=XXX
script since in your new script, you are doing cookies instead of sessions, and in the
?currency=XXX it has session related code

February 23, 2024 at 3:28 pm #15338492

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the details. One more doubt. How long you have been using this code on this site? Is it working as expected before upgrading to WPML 4.6.9?

add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );

function modify_client_currency( $current_currency ) {
if( !is_admin() ){
global $woocommerce;

if(isset($_GET['currency']) && !isset($_COOKIE['client_currency_cookie'])){
$currency = esc_attr( $_GET['currency'] );
$currency = strtoupper( $currency );
$currencies = get_woocommerce_currencies();
if ( array_key_exists($currency, $currencies)) {
if ( ! $woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie( true );
$woocommerce->session->set( 'client_currency', $currency );
} else {
$woocommerce->session->set( 'client_currency', $currency );
}
setcookie( "client_currency_cookie", $currency, 0, '/' );
} else {
return $current_currency;
}
}else{
if(isset($_COOKIE['client_currency_cookie'])){
$currency = $_COOKIE['client_currency_cookie'];
}else{
$currency = $current_currency;
}
}
return $currency;
}
}

add_action( 'wcml_switch_currency', 'my_custom_action_kideno', 10, 1 );
function my_custom_action_kideno( $new_currency ) {
global $woocommerce;
if ( !$woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie(true);
$woocommerce->session->set('client_currency', $new_currency);
}else{
$woocommerce->session->set('client_currency', $new_currency);
}
setcookie("client_currency_cookie", $new_currency,0,'/');
}

--
Thanks!

Bigul

February 23, 2024 at 3:43 pm #15338553

louisN-4

This code is on our site for 1 year
it seems you are not understanding, we already figured its not related to the upgrade of WPML - your 2nd tier pointed the fact that its a long time issue related to litespeed and WPML,

now you are on the path to resolving it, because you gave the code to change currency from session to cookie, BUT

1. i asked you if we can still use this code even though you gave a code to change to cookies when switching currencies
2. litespeed asks that also the url will change when switching currency

add_filter( 'wcml_client_currency', 'modify_client_currency', 10, 1 );

function modify_client_currency( $current_currency ) {
if( !is_admin() ){
global $woocommerce;

if(isset($_GET['currency']) && !isset($_COOKIE['client_currency_cookie'])){
$currency = esc_attr( $_GET['currency'] );
$currency = strtoupper( $currency );
$currencies = get_woocommerce_currencies();
if ( array_key_exists($currency, $currencies)) {
if ( ! $woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie( true );
$woocommerce->session->set( 'client_currency', $currency );
} else {
$woocommerce->session->set( 'client_currency', $currency );
}
setcookie( "client_currency_cookie", $currency, 0, '/' );
} else {
return $current_currency;
}
}else{
if(isset($_COOKIE['client_currency_cookie'])){
$currency = $_COOKIE['client_currency_cookie'];
}else{
$currency = $current_currency;
}
}
return $currency;
}
}

add_action( 'wcml_switch_currency', 'my_custom_action_kideno', 10, 1 );
function my_custom_action_kideno( $new_currency ) {
global $woocommerce;
if ( !$woocommerce->session->has_session() ) {
$woocommerce->session->set_customer_session_cookie(true);
$woocommerce->session->set('client_currency', $new_currency);
}else{
$woocommerce->session->set('client_currency', $new_currency);
}
setcookie("client_currency_cookie", $new_currency,0,'/');
}

February 23, 2024 at 4:55 pm #15338834

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the feedback and your patience. Sorry for the misunderstanding. I have escalated it to our second-tier team. We will get back to you as soon as possible. Please wait.

--
Thanks!

Bigul

February 26, 2024 at 3:48 pm #15345202

Bigul
Supporter

Languages: English (English )

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

Hello,

We have a request. Please take a full site backup{mandatroy} and try with the following code after removing the custom code you are currently using for the WCML Currency Switcher to store the value in a session.

// Use Cookie instead of WCSession
add_filter( 'wcml_user_store_strategy', function ( $strategy, $key ) {
    return 'cookie';
}, 10, 2 );
 
add_filter( 'wcml_is_cache_enabled_for_switching_currency', '__return_true' );

Because cookies are better for storing the currency values than sessions while we have enabled caches. Please check it and let us know your feedback.

--
Thanks!

Bigul

February 26, 2024 at 5:55 pm #15345729

louisN-4

Thanks for the above, before we change it

in our htacess we have the following:

<IfModule LiteSpeed>
RewriteRule .? - [E=Cache-Vary:client_currency_cookie]
</IfModule>

1. do we need to add something else so litespeed would work? what did they say with your discussion with them?

2. in the last video of litespeed, they showed me this video:
hidden link

in second 0:34, they show their new htaccess at the top they have

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !_lscache_vary= [NC]
RewriteCond %{QUERY_STRING} currency=([^&]+) [NC]
RewriteRule . %{ORG_REQ_URII}
CO=_lscoche_vary:wcml_currency\%3A%1:.litespeed.dev:86400:/,R-302,L] ErrorDocument 404 /speciol_404.php

i need to know what to put in the htaccess in order for your code to work well with the htaccess of litesped, so pages with ?currency=XXX will be cached

February 28, 2024 at 3:58 pm #15354928

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. I have shared the details with our team and waiting for their expert opinion on this. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

February 28, 2024 at 4:23 pm #15355011

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Udi,

Hope you are doing well.

Our team including myself having trouble understanding your queries so I will go one by one with your query. I hope it is fine.

In the past we were having issues with LiteSpeed cache and multicurrency as explained here https://wpml.org/forums/topic/follow-up-to-site-language-resetting-the-cache/page/2/#post-12922031

We did contact the LiteSpeed team and we got the response that they will find the solution. Since then we got no other client with the issue and no update from LiteSpeed.
I am really not sure what is the current status. But I will explain you in simple words.

For multicurrency LiteSpeed store the cookie and when you close the browser cookies is cleared then again you open the browser a non-cached version is served.
LiteSpeed keeps the cookie in the cache key so with/without cookie changes the key and clears the cache.

Now I am not sure what they have done to fix it but we will focus on what you need.

You need WCML to create a cookie for currency.
This code will do the job

// Use Cookie instead of WCSession
add_filter( 'wcml_user_store_strategy', function ( $strategy, $key ) {
    return 'cookie';
}, 10, 2 );

This will create the cookie name "wcml_client_currency"

You need query string in the URL with a currency code.

This code will do the job

add_filter( 'wcml_is_cache_enabled_for_switching_currency', '__return_true' );

The query string name will be "wcmlc".

I am not familiar with htaccess code, I mean what they are trying to do. It would be better if you can ask them what should be the cookie name and what should be the query string name then maybe we can adjust the code based on the response.

Or you can even ask them to adjust it based on my response.

From the video, it seems they have adjusted the there approach and even cookie is deleted the cache is not cleared if matches the query string.

I hope it helps.