This thread is resolved. Here is a description of the problem and solution.
Problem:
You are using WPML with WooCommerce Multilingual & Multicurrency on a catalogue-only site without any pricing, cart, or checkout functionalities. Despite disabling multcurrency, WCML is still setting 'wcml_client_currency' and 'wcml_client_currency_language' cookies, which prevent Varnish from caching guest responses.
Solution:
We recommend implementing a custom MU plugin to selectively remove these specific WCML cookies on guest WooCommerce catalogue pages, while preserving other necessary cookies like those for WPML language settings. Here's a step-by-step guide on how to do this:
<?php<br />/**<br /> * Plugin Name: Strip WCML Currency Cookies for Catalogue Cache<br /> * Description: Removes unnecessary WCML currency Set-Cookie headers for guest catalogue pages so Varnish can cache first responses.<br /> */<br /><br />add_action( 'template_redirect', function () {<br /> if ( is_admin() || is_user_logged_in() || wp_doing_ajax() ) {<br /> return;<br /> }<br /><br /> if ( function_exists( 'is_cart' ) && ( is_cart() || is_checkout() || is_account_page() ) ) {<br /> return;<br /> }<br /><br /> $is_catalogue_context =<br /> ( function_exists( 'is_shop' ) && is_shop() ) ||<br /> ( function_exists( 'is_product' ) && is_product() ) ||<br /> ( function_exists( 'is_product_category' ) && is_product_category() ) ||<br /> ( function_exists( 'is_product_tag' ) && is_product_tag() ) ||<br /> is_tax( get_object_taxonomies( 'product' ) );<br /><br /> if ( ! $is_catalogue_context ) {<br /> return;<br /> }<br /><br /> add_action( 'shutdown', function () {<br /> if ( headers_sent() ) {<br /> return;<br /> }<br /><br /> $headers = headers_list();<br /><br /> header_remove( 'Set-Cookie' );<br /><br /> foreach ( $headers as $header ) {<br /> if ( stripos( $header, 'Set-Cookie:' ) !== 0 ) {<br /> continue;<br /> }<br /><br /> if (<br /> stripos( $header, 'wcml_client_currency=' ) !== false ||<br /> stripos( $header, 'wcml_client_currency_language=' ) !== false<br /> ) {<br /> continue;<br /> }<br /><br /> header( $header, false );<br /> }<br /> }, 9999 );<br />}, 20 );<br />?>This approach is safe for a catalogue-only site and does not interfere with WPML's language handling or WooCommerce's product categorization and filtering. If you find this solution not applicable due to updates or it doesn't fit your case, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If issues persist, we highly recommend opening a new support ticket at WPML support forum.
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 3 replies, has 0 voices.
Last updated by 1 month, 1 week ago.
Assisted by: Bobby.