Geolocation with cache support
The geolocation and cache problem
Geolocation is powered by a WooCommerce PHP script which won’t run on cached pages. This can be confusing to customers. Here is an example of the problem:
- Hans from Germany visits the store and looks at a product.
- Hans sees the German price.
- The cache system saves the page in the cache.
- Charles from the UK visits the store and looks at the same product.
- As the page is cached, he sees German prices, rather than UK prices.
To solve this issue you have two options:
- Enable the option Load products price in background (recommended).
- Or, set the WooCommerce option Default Customer Address to Geolocate with page caching support.
Load products price in background
If you enable this option, Price Based on Country fires an AJAX request on each page to refresh prices dynamically.
To enable it go to WooCommerce → Settings → Zone Pricing → General options and select Load products price in background.
Load products price in background supports default WooCommerce product types (Simple, Virtual, Downloadable, External, Grouped and Variable).
Pro version adds support to WooCommerce Subscriptions, WooCommerce Product Bundles, WooCommerce Product Add-ons and WooCommerce Bookings.
WooCommerce Geolocate with page caching support
Since version 2.4, WooCommerce adds an option to set the user’s location called “Geolocation with page caching support”. When you activate this option WooCommerce fires a javascript redirection with an extra parameter v=xxxxx. This parameter causes cache invalidation, the new page (with the parameter) will cache separately.