jetpack
jetpack copied to clipboard
Add Support for WooCommerce Multilingual multicurrency
One of the developers of the WooCommerce Multilingual project reached out to me, asking if we could add support for their plugin to WP Super Cache. This page describes how to integrate it into a general caching plugin, and I think WP Super Cache would be easy to modify in that way.
It would probably best be done as a WP Super Cache plugin, so users of that plugin can activate that feature in WP Super Cache.
Or, the WooCommerce Multilingual plugin could ship their own plugin that would be copied into the WP Super Cache directory if they detected that WP Super Cache was installed.
The plugin could add the wcml_client_currency cookie to the rejected cookies list, to avoid caching those pages completely.
Or use the wp_cache_get_cookies_values cacheaction to add the cookie name/value to the cache key of the current page.
Hi @donnchawp!
I've ran some tests with the following snippet:
// This forces usage of cookie user storage instead of WC session
add_filter( 'wcml_user_store_strategy', function() {
return 'cookie';
} );
add_action( 'init', function() {
// This will include the "wcml_client_currency" cookie for the hash of the cached file.
do_action( 'wpsc_add_cookie', 'wcml_client_currency' );
} );
And that seems to work with the following acceptance steps:
- Setup WPML, WooCommerce, WooCommerce Multilingual
- Setup Multicurrency with at least one more currency
- Create and translate a product
- Install WordPress Super Cache and make sure shop and product are cached
- Visit as incognito user the product
- Switch currency
- Notice argument for switching is added - e.g. ?wcmlc=USD
- Remove argument and revisit product
- Notice previous currency is shown instead of the correct one
If you can prepare a dev version with the fix, we can test it on our side.
Thanks :)