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.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

This topic contains 11 replies, has 1 voice.

Last updated by Itamar 3 days, 10 hours ago.

Assisted by: Itamar.

Author Posts
June 18, 2025 at 9:40 am #17145390

saadI-4

Background of the issue:
I am trying to resolve an issue with WooCommerce and WPML where, after switching languages, the cart continues to use the original product and variation IDs from the previous language. This issue is most noticeable in the woocommerce_before_calculate_totals hook, where the product_id and variation_id still refer to the previous language versions. A hard refresh is required to get the correct translated IDs.

Symptoms:
The cart retains product IDs from the previous language after switching languages, even without any caching plugin active. The issue is most noticeable in the woocommerce_before_calculate_totals hook.

Questions:
Why does the cart retain product IDs from the previous language after switching?
How can I ensure the cart uses the correct translated IDs without requiring a hard refresh?

June 21, 2025 at 12:02 pm #17155955

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Welcome to WPML support. I will answer this ticket before the ticket is assigned to one of my colleagues.

To be able to give support we will need steps to reproduce the issue and we are not able to troubleshoot without having the context.

First thing is to check if the issue is happening on a minimal installation.

- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Switch to the default theme such as "TwentyTwenty" by going to "WordPress Dashboard > Appearance > themes".
- Go to "WordPress Dashboard > Plugins" and deactivate all plugins except WPML and its add-ons.
- Check if you can still recreate the issue.
- If not, re-activate your plugins one by one and check the issue each time to find out the plugin that causes the problem.

The best way is to show us how to replicate the issue on a clean installation, such as the one below:

hidden link

Thanks.

June 25, 2025 at 11:45 am #17168964

saadI-4

Hi,

Thank you for your response.

To help clarify the issue, I’ve already set up the environment as requested and added everything needed to reproduce the issue:

1) WPML and WooCommerce are installed in the given environment.

2) I created a custom plugin called "Test Issue Plugin", which simply hooks into the woocommerce_before_calculate_totals action and outputs the product ID along with the current language for testing purposes.

3) The product ID in English is 41, and in Arabic is 42. As shown in the screen recording below, when switching the site language, the cart continues to use the previously loaded product ID. The ID does not update until the page is manually refreshed, indicating the product object is being cached and not reloaded based on the new language.

4) Just to clarify, we are not the ones using woocommerce_before_calculate_totals in production. However, after investigating the issue, we noticed that multiple plugins rely on this hook, and the root cause appears to stem from this cached product ID behavior.

Here is a screen recording that demonstrates the issue clearly:
hidden link

June 25, 2025 at 7:07 pm #17170731

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I'll continue to help you with this issue.

I'm consulting our second-tier supporters about your case and will update you here once I have their reply.

I appreciate your patience.
Itamar.

June 26, 2025 at 12:00 pm #17173286

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Thank you for your detailed explanation and for setting up the sandbox.

Our second-tier supporter reviewed the case and confirmed they were able to reproduce the issue as described:

1. When you add a product to the cart and view the cart in one language, then switch languages using the language switcher, the translated product is displayed correctly on the cart page.

2. However, at that moment (during the page load), when the `woocommerce_before_calculate_totals` hook is triggered, the cart still references the original language product ID, not the translated one.

3. If you then manually reload the cart page in the new language, the hook will correctly reflect the translated product ID.

At this stage, they suggest that before we consider further escalation, it would be helpful if you could share **real-world use cases** where this behavior causes practical issues, especially considering that it only occurs when users manually switch languages after adding a product to the cart.

If it's a hypothetical concern, it's unlikely to move forward. However, if there are actual use cases or third-party plugins affected by this, we’ll be able to assess its impact more accurately and decide on the next steps accordingly.

Regards,
Itamar.

June 29, 2025 at 10:15 am #17180098

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Our third-tier supporter added the following information.

The product ID is updated properly. The client code is unreliable and shows the product before the updating of the ID of the product. This is probably due to wrong timings on when the user gets the ID.
If you refresh again the cart, it will show the proper ID for the proper language.

Please let me know if you require additional assistance with this issue.

Regards,
Itamar.

June 29, 2025 at 12:11 pm #17180208

saadI-4

Hi,

Thank you for your reply.

We understand your point, but we’d like to clarify that "woocommerce_before_calculate_totals" hook is a core and widely adopted WooCommerce hook. It is triggered on every cart recalculation and is intended specifically for adjusting cart item data such as product prices, discounts, and fees before the totals are finalized. This makes it a reliable and essential part of WooCommerce's pricing flow. Additionally, many plugins also depend on this hook, one example being the "Buy One Get One Free for WooCommerce" plugin:
https://woocommerce.com/products/buy-one-get-one-free/

To better demonstrate the issue, we’ve replicated it again in the provided clean environment:

1) We installed the Buy One Get One Free for WooCommerce plugin.

2) We added three simple products priced at $10 each and created their Arabic translations.

3) We configured a BOGO rule: Buy 2, get 1 free.

4) In the video, you can see the expected behavior — when 3 products are added in English, the customer is charged $20 (2 paid + 1 free), which is correct. However, when switching to Arabic, the cart suddenly shows only 1 paid product ($10) and gives 2 for free, which is incorrect. The totals are only recalculated correctly after a manual page refresh.

Here’s a screen recording of the issue:
hidden link

This behavior suggests that cart item product data is not being properly updated or reloaded during language switches, which can impact not just our custom logic, but any plugin relying on accurate product data during cart calculations.

We hope this better illustrates the issue.

June 30, 2025 at 12:48 pm #17184299

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Thanks for replicating this issue with the Buy One Get One Free for WooCommerce plugin.
While I'm consulting with our second-tier supporters, could you please let me know if you use this plugin on your site?

Regards,
Itamar.

July 1, 2025 at 7:47 am #17186979

saadI-4

Hi,

Yes, we are using the Buy One Get One Free for WooCommerce plugin on our site.

Please let me know if you need any further information or details to assist with the investigation.

Best regards

July 1, 2025 at 11:01 am #17188048

Carlos Rojas
WPML Supporter since 03/2017

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

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

Hello,
My name is Carlos, and I’ll be assisting you today in place of Itamar.

Our third-tier specialists provided this workaround. Please paste the code in the functions.php file located in the active theme's folder and double-check if the issue has disappeared:

add_action( 'wpml_language_has_switched', function( $new_lang, $cookie_lang, $original_lang ) {
    if ( $new_lang !== $original_lang ) {
        // Set transient/session to trigger a reload on the next request
        setcookie( 'wpml_lang_switched', '1', time() + 10, '/' );
    }
}, 10, 3 );

add_action( 'template_redirect', function() {
    if ( isset($_COOKIE['wpml_lang_switched']) ) {
        // Remove the cookie to avoid infinite loop
        setcookie( 'wpml_lang_switched', '', time() - 3600, '/' );

        // Force full page reload — redirect to the current URL
        wp_redirect( home_url( add_query_arg( null, null ) ) );
        exit;
    }
});

Best regards,
Carlos

July 2, 2025 at 1:56 pm #17193452

saadI-4

Hi,

Thank you for your reply.

I’ve tested the suggested code in the given environment, but unfortunately, the issue still persists, and the solution didn’t resolve the problem.

Please let me know if there's anything else.

Best regards,

July 3, 2025 at 8:30 am #17195804

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I apologize that the provided code did not resolve the issue.

Unfortunately, the Buy One Get One Free for WooCommerce plugin is unknown to us. I searched our system and could see that none of our users is using it. I'm sorry, but under these compatibility circumstances, we can't support this plugin. You can contact the authors of the Buy One Get One Free for WooCommerce plugin and request their assistance with this issue. Alternatively, please consider using a similar plugin with similar features that is officially compatible with WooCommerce Multilingual & Multicurrency. For example, please see the WooCommerce Discount Manager plugin: https://wpml.org/plugin/woocommerce-discount-manager/. Or search for another similar plugin in the following link: https://wpml.org/plugin-functionality/woocommerce-extension/.

Best Regards,
Itamar.