Geolocation with cache support

The geolocation and cache problem

Geolocation is powered by a WooCommerce PHP script which won’t run on cached pages. Here is an example of the problem:

  1. Hans from Germany visits the store and looks at a product.
  2. Hans sees the German price.
  3. The cache system saves the page in the cache.
  4. Charles from the UK visits the store and looks at the same product.
  5. As the page is cached, he sees German prices rather than UK prices.

This problem confuses customers.

Load products price in the background

Price Based on Country includes an option that refreshes the product’s prices on each page using Javascript and AJAX to solve this issue. Here is how this works:

  1. The plugin adds an HTML wrapper to each product’s price on the page. This wrapper matches each piece of HTML with the product.
  2. When a customer visits a page on the site, an AJAX call is fired in the background, which returns the price of each product.
  3. The Javascript replaces all product prices on the page with the value returned by the AJAX call.
The Geolocation setup wizard enables this option if it detects a cache plugin.

To enable/disable the “Load products price in the background” option, go to WooCommerce > Settings > Pricing zones > Options:

WooCommerce Geolocation with cache support

Currently, this option does not support WooCommerce Composite Products.

The WooCommerce option “Geolocate with page caching support.”

As an alternative to the “Load products price in the background” option, WooCommerce includes another feature that also solves the geolocation and cache problem.
This feature fires a Javascript redirection with an extra parameter v=xxxxx. This parameter causes cache invalidation. The new page (with the parameter) will cache separately.

To enable it, set the “Default customer location” option to “Geolocate (with page caching support).”

Default customer location

You must manually clear the cache of the cache plugin after changing the “Default customer location” option.

See also