Caching WPML currency switcher
-
Dear Support,
I am contacting you after having spoken to WPML support. In my website I am using a currency switcher provided by WPML, however when I switch currency the page is not automatically updated. It requires my to manually refresh the page to see the change. Now, this is not user friendly and very luckily due to the caching mechanism.
Is there a way to exclude the currency switch from the caching?
Another user provided the below reported solution applicable to websites using a different platform. I am wondering if this solution could by adapted for SG Optimizer. Could you please in case advise how to adapt it or provide a different solution?
Thanks in advance,
Fabio
1: Add the following php code via either a code editor plugin or via the functions.php file somewhere or in child theme’s functions.php file. This will create the “wcml_custom_currency_cookie” cookie:
?
?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’);?
?2: Exclude cache for the $wcml_custom_currency_cookie http_cookie via nginx (Us in Support can only modify/edit these since we’re a managed hosting platform.
?
?3: Strip all $http_cookies that are still cached on cache HITS, this will avoid the cookie from being set up on pages that hit the Kinsta cache to avoid bypassing Kinsta cache where we don’t need to bypass Kinsta cache. As you know, cache on WordPress is very important to keep site speed optimized!The page I need help with: [log in to see the link]
- The topic ‘Caching WPML currency switcher’ is closed to new replies.