Geolocation for Woocommerce not working good with Cloudflare

Hi! We have currency plugin that works with your Woocommerce Geolocation (site: After we installed Cloudflare, Geolocation not working right. I’m living in Estonia, but it shows me that Im from Sweden or sometimes from Russia (I can see it in checkout page shipping country) and currency changes to RUB or Sweden KR.

Do you know how the currency plugin determines geolocation? If it uses visitor IP address and the server has not been properly configured to work with Cloudflare, it may get incorrect IP address information.

1 Like

Its using shipping country for needed currency. In Woocommerce settings I set “Default Contry Location” to “Geolocate” (Its using MaxMind standart Woocommerce integration). So when I open site, the site thinks that Im from Sweden and set for me Sweden KR currency, before Cloudflare its worked good.

Thank you!

If you can’t get it to track the IP address as outlined in the article I linked to, can you customize it to use other methods?

I added this code to header.php

Purged cache, but its not helped :frowning:
Thank you!

Are you using Apache or Nginx?

We have hosting, there I created Wordpress App, as I understand its using Apache, for configure Apache I can edit only .htaccess file. And I can add node.js application

Thank you!

Ok, that makes things more complicated.

May I ask where you have implemented this code?

Which file exactly was it added to?

I added it in header.php (Theme files)

Thats not correct, please add it into your “wp-config.php” file, so it applies globaly on your Wordpress installation… not just the Theme.
Also add it at the very top (just right after the opening PHP tag).

Then report back, if it worked and please provide a screenshot of the file where you have implemented it now, so we can assist and validate it’s done right.

Still thinks that Im from Sweden :cry:

Can you try this snippet?

if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {

Source: #1 GitHub, #2 StackOverFlow #3 GitHub

I am afraid lukapaunovic got that wrong. That header always is a single-value field.

1 Like

Thanks, I updated the snippet.

1 Like

Ah, not working ( , maybe problem in Cloudflare settings?

Thank you for help!


We are having the same exact problem.

We have tried to ■■■ those snippets with no luck!

Thank you.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.