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
| Priority | Source | Condition |
|---|---|---|
| 1 (highest) | Shipping address | Visitor is logged in and has a saved shipping country |
| 2 | Billing address | Visitor is logged in and has a saved billing country |
| 3 | WooCommerce session cache | Country was detected in a previous request this session |
| 4 | Transient cache | IP-detected country stored for up to 1 hour |
| 5 | IP geolocation | WooCommerce's MaxMind GeoLite2 database lookup |
| 6 (fallback) | Store base country | Used 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:
HTTP_CF_CONNECTING_IP(Cloudflare)HTTP_X_FORWARDED_FORHTTP_X_REAL_IPREMOTE_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: