Documentation
GeoBlock
How Geolocation Works

How Geolocation Works

GeoBlock detects the visitor's country through a prioritised cascade. It uses the most accurate source available and falls back to less precise methods when necessary.

Detection Priority

PrioritySourceCondition
1 (highest)Shipping addressVisitor is logged in and has a saved shipping country
2Billing addressVisitor is logged in and has a saved billing country
3WooCommerce session cacheCountry was detected in a previous request this session
4Transient cacheIP-detected country stored for up to 1 hour
5IP geolocationWooCommerce's MaxMind GeoLite2 database lookup
6 (fallback)Store base countryUsed when all other methods fail

Steps 1–3 are skipped when Force Geolocation is enabled. See Advanced Settings.


Caching

Country results are cached in two layers to minimise database lookups:

  • WooCommerce session: Persists for the duration of the visitor's session.
  • WordPress transient: Keyed by a hash of the visitor's IP address; expires after 1 hour.

Proxy and CDN Support

When detecting the visitor's IP, GeoBlock checks these headers in order, taking the first valid public IP found:

  1. HTTP_CF_CONNECTING_IP (Cloudflare)
  2. HTTP_X_FORWARDED_FOR
  3. HTTP_X_REAL_IP
  4. REMOTE_ADDR

Comma-separated values in X-Forwarded-For are split and the first public IP is used.


Geolocation Database

GeoBlock uses WooCommerce's built-in WC_Geolocation class, which reads from the MaxMind GeoLite2 country database. No API key is required - WooCommerce manages the database download automatically when geolocation is enabled.

To ensure the database is available:

Open WooCommerce Settings

Go to WooCommerce → Settings → General.

Enable geolocation

Set Default customer location to Geolocate or Geolocate (with page caching support).

Save

Click Save changes. WooCommerce will schedule the database download automatically.