Title: Cloudflare IP Header
Last modified: April 22, 2025

---

# Cloudflare IP Header

 *  [fill64](https://wordpress.org/support/users/fill64/)
 * (@fill64)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/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?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [kuldipzorem](https://wordpress.org/support/users/kuldipzorem/)
 * (@kuldipzorem)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18430661)
 * Hi [@fill64](https://wordpress.org/support/users/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,
   Kuldip
 *  Thread Starter [fill64](https://wordpress.org/support/users/fill64/)
 * (@fill64)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18432402)
 * Dear [@kuldipzorem](https://wordpress.org/support/users/kuldipzorem/)
 * I had set in Cloudflare – Rules -> Page Rules – rule to:
   **Domain:** [https://mydomain.com/](https://mydomain.com/)**
   Cache level:** cache everithing**Edge cache TTL**: 2 hoursI removed that rule.
 * And in Caching – Configuration – Cache Level I have set to **Standard**
 * Did I forget something? Thats ok?
   Thank you
 *  Plugin Author [kuldipzorem](https://wordpress.org/support/users/kuldipzorem/)
 * (@kuldipzorem)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18432945)
 * Hi [@fill64](https://wordpress.org/support/users/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,
   Kuldip
 *  Thread Starter [fill64](https://wordpress.org/support/users/fill64/)
 * (@fill64)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18443576)
 * Hi [@kuldipzorem](https://wordpress.org/support/users/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-IP` and `CF-IPCountry` headers.
    - My server (Websupport) uses **Apache with `mod_remoteip` enabled**, so `REMOTE_ADDR`
      is 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_ip`
   filter when using Cloudflare. 👉 Question:
 * Can you confirm:
    1. Does your plugin rely on `WC_Geolocation::geolocate_ip()` directly?
    2. Does it cache the result (e.g. from cookie)?
    3. 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](https://wordpress.org/support/users/fill64/).
 *  Thread Starter [fill64](https://wordpress.org/support/users/fill64/)
 * (@fill64)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18449110)
 * Dear [@kuldipzorem](https://wordpress.org/support/users/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
 *  Plugin Author [kuldipzorem](https://wordpress.org/support/users/kuldipzorem/)
 * (@kuldipzorem)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18449556)
 * Hi [@fill64](https://wordpress.org/support/users/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,
   Kuldip
 *  Thread Starter [fill64](https://wordpress.org/support/users/fill64/)
 * (@fill64)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18452533)
 * Dear [@kuldipzorem](https://wordpress.org/support/users/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.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Cloudflare IP Header’ is closed to new replies.

 * ![](https://ps.w.org/woo-product-country-base-restrictions/assets/icon-256x256.
   png?rev=2808588)
 * [Country Based Restrictions for WooCommerce](https://wordpress.org/plugins/woo-product-country-base-restrictions/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-product-country-base-restrictions/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-product-country-base-restrictions/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-product-country-base-restrictions/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-product-country-base-restrictions/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-product-country-base-restrictions/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [fill64](https://wordpress.org/support/users/fill64/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/cloudflare-ip-header/#post-18452533)
 * Status: not resolved