Cloudflare IP Header
-
Hi I use the free version of your plugin. Until recently everything worked without problems. I had to deploy cloudflare (free version) on my eshop because of attacks. After enabling cloudflare your plugin stopped working properly. I tested it through different VPNs and contorlated to see if I am really in the country I have set to not show products and it shows. Can you help me please?
-
Hi @fill64,
It might be a caching issue with Cloudflare. Please try completely disabling the cache from Cloudflare and then check the issue again.
Let me know how it goes.
Thanks,
KuldipDear @kuldipzorem
I had set in Cloudflare – Rules -> Page Rules – rule to:
Domain: https://mydomain.com/
Cache level: cache everithing
Edge cache TTL: 2 hours
I removed that rule.And in Caching – Configuration – Cache Level I have set to Standard
Did I forget something? Thats ok?
Thank youHi @fill64,
Okay, but if there’s an option to remove the standard cache level, please go ahead and remove it. Otherwise, this configuration is fine.
Also, please ensure that no cookies are set in the cache.
Check the issue and let me know how it’s working.
Thanks,
KuldipHi @kuldipzorem
Thanks for your response earlier. I wanted to give you a full update on what we’ve tried so far, hoping this gives better insight.
✅ Context:
I use your plugin to hide certain products for visitors from specific countries (e.g. UAE). It worked fine until I activated Cloudflare (free plan) to mitigate bot attacks. After activating Cloudflare, users from restricted countries started seeing the hidden products again. 🔍 What we’ve done so far:- Cloudflare proxy is active (orange cloud).
- Cloudflare correctly sends
CF-Connecting-IPandCF-IPCountryheaders. - My server (Websupport) uses Apache with
mod_remoteipenabled, soREMOTE_ADDRis correctly populated with the visitor’s real IP. - Verified that:
$_SERVER['REMOTE_ADDR']= real client IP (e.g. UAE test IP).WC_Geolocation::geolocate_ip()returns correct country (e.g.AE).
- Added this to
functions.php:
add_filter('woocommerce_geolocation_ip', function($ip) { return $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $ip; }); add_filter('option_wpcbr_force_geo_location', '__return_true');🧪 What works and what doesn’t:- ✅ When Cloudflare is paused, everything works fine — user in UAE sees no restricted products.
- ❌ When Cloudflare is active, and the correct IP is passed, the user sees the restricted products again.
🧼 Cache cleared:
- Cloudflare cache was purged completely.
- Development Mode enabled.
- Browsers tested in incognito with no cookies.
- Page rules and Cache Rules were temporarily removed.
🤔 My assumption:
It seems your plugin is possibly caching the country in a cookie or not re-evaluating the IP if one was cached previously — or it may not respect the
woocommerce_geolocation_ipfilter when using Cloudflare. 👉 Question:Can you confirm:
- Does your plugin rely on
WC_Geolocation::geolocate_ip()directly? - Does it cache the result (e.g. from cookie)?
- Can we force it to always re-check based on real IP or override with a hook?
Thank you for your time — we’ve come very far in debugging this and appreciate any input you might have to make it work reliably with Cloudflare.
Best regards,
-
This reply was modified 1 year, 1 month ago by
fill64.
Dear @kuldipzorem
Do you have any new advice or procedures on what I should do? I’m already desperate that it’s not working and I don’t know what to do anymore.
Thank you
Hi @fill64,
Thanks for your questions. Please find my answers below:
Q: Does your plugin rely on WC_Geolocation::geolocate_ip() directly?
A: Yes, our plugin uses WC_Geolocation::geolocate_ip() to detect the visitor’s country based on their IP address.Q: Does it cache the result (e.g. from cookie)?
A: Yes, the detected country is stored in a cookie after the initial geolocation lookup.Q: Can we force it to always re-check based on real IP or override with a hook?
A: Currently, this isn’t supported. Our plugin does not yet offer a way to force re-checks or override the geolocation via a hook.Let me know if you have any other questions or need further assistance.
Thanks,
KuldipDear @kuldipzorem,
Thank you for the support I finally solved it with my own custom plugin since I couldn’t get yours to cooperate as I needed. Anyway without CloudFlare your plugin is functional at least for me on my site.
The topic ‘Cloudflare IP Header’ is closed to new replies.