Skip Navigation

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

Problem:
The client is experiencing issues with currency shifting and stock updates on their WooCommerce site when NitroPack caching is enabled. The currency selection is supposed to be based on the client's country, but it sometimes fails to change correctly. Additionally, product stock levels are not updating as expected. NitroPack support inquired about the use of variation cookies related to the WooCommerce Multilingual plugin, which the client could not find in the session.

Solution:
1) We confirmed that the necessary cookies for handling languages and currencies already exist, and one of them is a NitroPack cookie.
2) We invited NitroPack to collaborate with us through the Go Global Program to ensure compatibility between our plugins.
3) We provided a code snippet to create a custom cookie for currency:

function wcml_set_custom_currency_cookie( $currency = false ) {<br />if ( is_admin() && !( defined('DOING_AJAX') && DOING_AJAX ) )<br />return;<br />if ( !empty( $currency ) ) {<br />setcookie('wcml_custom_currency_cookie', $currency, time() + 60*60*24*7, '/');<br />return;<br />}<br />if ( empty( $_COOKIE['wcml_custom_currency_cookie'] ) && function_exists( 'get_woocommerce_currency' ) ) {<br />setcookie('wcml_custom_currency_cookie', get_woocommerce_currency(), time() + 60*60*24*7, '/');<br />}<br />}<br />add_action('wcml_switch_currency', 'wcml_set_custom_currency_cookie');<br />add_action('init', 'wcml_set_custom_currency_cookie');

4) We advised the client to add this code to their functions.php file and to ask NitroPack how to exclude the 'wcml_custom_currency_cookie' from caching.

If this solution does not seem relevant to your situation, 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 5 replies, has 2 voices.

Last updated by andersE-18 3 years, 8 months ago.

Assisted by: Alejandro.

Author Posts
September 6, 2021 at 6:44 am #9528457

andersE-18

We have problem with currency shifting and stock updates on products.

The plugin we use is WooCommerce Multilingual/Multi-currency and for cache we use NitroPack. When we enable NitroPack this problem appears.

Choice of currency is done by client country. Sometimes is not changing correctly.
Also the product stock doesn't update sometimes.

I have been in contact with NitroPack support and they throw me this question that i don't have an answer for:

---
Can you please confirm if the plugin's configuration allows you to set/use variation cookies? If it allows, you can add the following variation cookies and hopefully this should solve the issue:

wcml_client_currency
wcml_client_currency_language
wcml_client_country
---

I dont see those cookies in the session...

The site is: hidden link

September 8, 2021 at 6:05 am #9544603

andersE-18

Hello!

Here is the answer from NitroPack:

---
We were not able to completely understood the response from WPML Support. Do you need to create the 4 mentioned cookies by them ( wp-wpml_current_language; _icl_visitor_lang_js; _wcml_dashboard_currency; np_wc_currency) or you need to disable the additional creation of _wcml_dashboard_currency and np_wc_currency?
Sincerely,
Paul V.
Technical Support at NitroPack
---

Can you please specify what your plugin need to function properly?

// Anders

September 8, 2021 at 6:13 am #9544621

Alejandro
WPML Supporter since 02/2018

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

You can please let them know that those cookies already exist and they are the ones that handle the languages and the currencies (one of them is even THEIR cookie!).

The reason why i have you those cookie names is so nitrpack could tell you if they could disable caching those cookies so they can change values and have multicurrency working.

Please invite NitroPack to work with us by joining the Go Global Program found here: https://wpml.org/documentation/support/go-global-program/

That way we can make both our plugins compatible with each other.

Regards.

September 10, 2021 at 11:47 am #9562915

andersE-18

Hello!

Now it's starting to make sense. There are no cookie that tells what currency is selected. Do i need to add that programmatically?

Reply from NitroPack.
-------
Bobby (NitroPack)
Sep 10, 2021, 11:02 GMT+3
Hi, Anders,

I have sent the link for Go Global Program to our dev team.

As for the cookies we do not need to exclude them but we can add them on our side as variation cookies. That way we will create separate version of the page for every different value of those cookies.

I have checked the cookies on the website and can't see them:

[image uploded]

Those are all cookies without NitroPack, the website loaded from Sweden and the currency was changed to kr. I can't see which one is the one responsible for the currency change.

I have also added all those cookies as variation cookies just in case. Here are all cookies that are added as variation cookies at the moemnt:

[image uploded]

However, I'm now observing another strange behavior.

When visiting from Bulgaria I get prices in EUR and when I switch to Sweden the currency changes but not to kr but to British bound.

Could you please forward this to the WPML team and ask the to clarify which cookie am I missing.
Kind regards,
Bobby
Technical Support Engineer at NitroPack
--------

SL-0086.jpg
September 11, 2021 at 8:23 am #9568009

Alejandro
WPML Supporter since 02/2018

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Let's try the following:

1) Let's create a cookie here:

function wcml_set_custom_currency_cookie( $currency = false ) {
if ( is_admin() && !( defined('DOING_AJAX') && DOING_AJAX ) )
return;
if ( !empty( $currency ) ) {
setcookie('wcml_custom_currency_cookie', $currency, time() + 60*60*24*7, '/');
return;
}
if ( empty( $_COOKIE['wcml_custom_currency_cookie'] ) && function_exists( 'get_woocommerce_currency' ) ) {
setcookie('wcml_custom_currency_cookie', get_woocommerce_currency(), time() + 60*60*24*7, '/');
}
}
add_action('wcml_switch_currency', 'wcml_set_custom_currency_cookie');
add_action('init', 'wcml_set_custom_currency_cookie');

that function can be added to your functions.php file.

2) Now ask nitropack how you can exclude this newly created cookie from the cache plugin "wcml_custom_currency_cookie"

Maybe that will do it 🙂

September 12, 2021 at 10:35 am #9571027

andersE-18

In NitroPack i can add "variation cookies". They causes them to create different cached version of the page depending of the content of that cookie.

I added your code, and added that cookie in NitroPack as a variation cookie and that seems to have solved the issue.

Thank you!