Back to Docs

Will the Plugin Work with Caching Plugins and CDN Services?

WC Country Restrictions uses IP-based geolocation to determine user location and apply visibility rules. While the plugin works out of the box, there are considerations when using caching plugins and CDN services that affect how geolocation works.

Important Considerations:

  • Dynamic Content Requires Correct IP Detection
    Ensure your server or CDN forwards the real user IP address. Services like Cloudflare require enabling “True Client IP” or similar settings.
  • Use AJAX-Based Geolocation (Recommended)
    To overcome full-page caching limitations, the plugin uses AJAX to detect the user’s country and apply restrictions dynamically.
    This means hidden products or custom buttons/messages load after the page finishes rendering.
  • Exclude Sensitive Pages from Caching
    Exclude pages like the shop archive or product pages from aggressive caching if visibility issues arise.
    In your caching plugin (e.g., WP Rocket, W3 Total Cache), add product pages or archives to the “Never Cache” list if needed.
  • Geolocation Settings in WooCommerce
    In WooCommerce > Settings > General, make sure the Default customer location is set to:
    “Geolocate (with page caching support)” for optimal compatibility.
    This enables WooCommerce to detect the country even when page caching is used.

CDN Consideration (e.g., Cloudflare, BunnyCDN):

  • Ensure that the CDN is not caching full pages that bypass dynamic scripts.
  • Use Edge Rules or Page Rules to allow proper functioning of the plugin’s dynamic location-based behavior.

The plugin is designed to work well with caching and CDN tools, but some manual configuration may be needed to ensure proper IP detection and country-based logic execution.