Note

Although this article refers to the Currency Switcher for WooCommerce, the possible causes of issues apply to all the Aelia plugins that include a geolocation feature.


The geolocation logic has been thoroughly tested. When it looks like it's not working properly, the issue is almost always due to a misconfiguration or to external causes. Most of the possible causes can be found below. 


Important

  • Please review each section carefully. It's easy to overlook some settings, such as caching, or a non-standard reverse proxy, and assume that the geolocation feature itself is not working properly. Based on our experience, that is rarely the case. The root cause of geolocation issue is almost invariably external to our plugins.
  • Before you perform the troubleshooting steps, we recommend that you enable the debug log in the Currency Switcher settings. The log will contain entries showing what IP address was received by the Currency Switcher, and to which country and currency such address was resolved. You can find a step by step guide, showing how to enable and review the log, here: How to view the geolocation resolution log from the Currency Switcher.


1. The visitor has already a country/currency assigned to him/her

Geolocation is triggered once per visitor. The detected information (country, currency, etc) is then stored against visitor's session and, if he/she is logged in, against the profile, in the database. The stored information is then used from that moment on, and no further geolocation is performed.


During testing, it's important to use private/incognito browser sessions, and close them after each visit. This ensures that the cookies set by the plugins to track the detected country and currency are deleted, and that the geolocation is performed again at the next visit.


2. The geolocation feature is disabled

The geolocation feature is disabled by default. To enable it, go to Currency Switcher Options > Geolocation, tick the Geolocation option and save the plugin settings.


3. The exchange rate for one or more currencies is missing or not valid

As indicated in Currency Switcher Options page, the exchange rate for each currency is compulsory, as it's used for reporting. If this information is missing, the affected currency is ignored by the plugin. When a currency is ignored by the Currency Switcher, it cannot be assigned to a visitor after detecting his geolocation, therefore the Currency Switcher will use the default currency instead.


It's also important to note that exchange rates must use the point as a decimal separator, and they must not contain any thousand separator. For example, 123.456 (note the point) is a valid exchange rate, while 123,456 (using the comma) is not. An exchange rate using the incorrect separator would be considered invalid, and that would also cause the currency to be ignored.


4. A caching system, or plugin, is serving stale content
This is one of the most common issues on an ecommerce site, and it accounts for more than half the cases in which the geolocation doesn't seem to be working.


If you use plugins like W3 Total Cache or Super Cache, or a caching service (Squid, Varnish, etc), your server may be serving your visitors stale pages. In such case, the geolocation logic is not even invoked, thus making it look like it's not working. This is described in more details in the following article: The currency conversion/detection doesn't seem to work with caching enabled.


To fix this issue, there are two possible solutions:

  • If your caching system/plugin supports dynamic caching, you will simply have to configure it correctly. You can find the instructions to configure dynamic caching for some common caching systems in our knowledge base: How to add dynamic caching to your site.
  • If your caching system/plugin does not support dynamic caching, you will have to disable caching on catalogue pages and product pages, or use a workaround solution such as our WooCommerce Cache Handler plugin. The article about dynamic caching, linked above, also covers this case and provides further details.


5. The user accessed the site when the Currency Switcher was active, but before geolocation was enabled

Geolocation detection is executed only the first time a visitor comes to your site. If a visitor comes to your site when geolocation detection is disabled, he is assigned the default currency, which then persists for subsequent visits. For more information, please refer to the following article: How does Currency Switcher geolocation detection mechanism work?


6. Your site is behind CloudFlare

CloudFlare supports dynamic only on Enterprise plans. Other plans use a static caching system, that may serve incorrect content to your visitors. To solve the issue, you will have to install our WooCommerce Cache Handler plugin (please make sure that the caching level is set to standard in CloudFlare settings), or disable CloudFlare's page caching altogether. Caching of resources, such as JavaScript, CSS and images, can be left enabled, as it doesn't have an impact on the content of the page. For more information, please refer to the related knowledge base article: How to add dynamic caching to your site.


7. Your site is behind Sucuri CloudProxy

Sucuri replaces the visitor's IP with their own, making all users appear with the same IP address. This prevents the Currency Switcher from detecting visitor's location. This is documented in the Sucuri knowledge base: Sucuri - Same IP for All Users.


Sucuri CloudProxy also doesn't support dynamic caching, and might serve the wrong content to your visitors. Due to that, you will have to disable Sucuri's caching, or use a workaround such as our WooCommerce Cache Handler plugin. For more information, please refer to the related knowledge base article: How to add dynamic caching to your site.


For more information, please refer to the related knowledge base article: How to add dynamic caching to your site.


8. Your site is behind a reverse proxy that uses non-standard headers

The Currency Switcher can deal with standard reverse proxies, but some of them use non-standard headers. In such case, some custom code might be needed to properly determine the visitor's IP address. Your code should add a wc_aelia_currencyswitcher_visitor_ip filter and return the correct IP address, based on your server's configuration.


For reference, the geolocation feature looks for visitor's IP address in the following headers (order by priority, highest to lowest):

  1. HTTP_CLIENT_IP
  2. HTTP_X_FORWARDED_FOR
  3. HTTP_X_REAL_IP
  4. REMOTE_ADDR
As soon as one of such values is found, the detection takes it as visitor's IP address and performs the detection using it. If the headers contain an IP address that is not the one from the visitor, then the geolocation will return the wrong country code. In such case, you should contact your hosting provider, to ensure that the server passes the correct values in the respective headers.


We also recommend to read the following articles, which will help checking what IP address is passed by the server to the geolocation logic:


8.1 Special note about HostGator, Bluehost and related providers

The servers from HostGator and Bluehost are known to use a reverse proxy that hides your visitor's real IP address, by storing it in the incorrect header. The visitor's address should be stored in header HTTP_X_FORWARDED_FOR, whereas the proxy's address should be in header REMOTE_ADDR, but they do the opposite. Due to that, the geolocation receives the wrong IP address, which resolves to your site's location (usually, Provo, Utah, United States). This issue is something that must fixed by the hosting provider. We already informed them years ago, but they don't seem to have much interest in addressing the issue.

As a temporary patch, we prepared a small plugin that swaps the headers, so that the correct IP address can be passed to the geolocation: wc-aelia-fix-bluehost-ip-headers.zip. The patch is a simple "install and activate" plugin. This should fix the issue, at least temporarily, by extracting visitor's IP address from the headers used by HostGator and Bluehost and passing it to the geolocation.

Important

Fixing the issue caused by the incorrectly configured reverse proxies remains a responsibility of the hosting providers to address. The "patch" plugin is provided as is, as a courtesy, without guarantees. We won't be able to offer assistance in case it's not sufficient to address the issue. 


9. Your visitors are using a proxy

If visitors are coming to your site via a proxy server, then they IP address has been replaced by the one used by the proxy server. In such case, there is no way to detect the original IP address, as the site is actually not communicating with the visitor's computer, but with the proxy itself.


10. Your site is running an old version of the Aelia plugins

Before you update WooCommerce, you must always make sure that you update the Aelia plugins to the latest versions. You can download them from the email you received when you completed your orders, or from the My Account section on our site.


There may be other factors that can impact on the geolocation mechanism, which vary depending on the specific condition and environment. Should you encounter any issues with the geolocation feature and none of the above solution seems to apply, please feel free to open a support ticket and we will be happy to assist you.


11. Another plugin might be interfering with the geolocation and currency selection features

Other plugins may be preventing the geolocation and automatic currency selection features from working correctly. If you use plugins that introduce features related to currency management, you will have to disable them to prevent conflicts.


To determine if one or more of the installed plugins are interfering with the geolocation feature, you can simply go by exclusion:

  1. Disable one of the 3rd party plugins (except WooCommerce and plugins developed by Aelia).
  2. Reload the site, ensuring that you follow the instructions to test the geolocation.
  3. If the issue persists, repeat from #1 with the next plugin. If not, then you will have an indication that the last plugin you disabled might be contributing to the issue. In such case, you can inform both us and its author, so that we can find a solution.


12. There could be some custom code setting the active currency

The Currency Switcher allows to set the currency via code, by writing a simple filter. If you, or one of your developers, wrote such customisation in the past, the code may still be in your theme's functions.php, overriding the currency detection.


13. Your site is running on a hosting provider that hides the real IP Address of your visitors

Some hosting providers rely on external services, such as Google Cloud. These services can hide the real IP address of your visitors, replacing it with the address of one of the services from their infrastructure. 


This is a known issue with some hosting providers, that doesn't depend on the Aelia plugins. If you purchased the optional GeoTargeting addon from WP Engine, you can use a customisation to take the geolocation details directly from the hosting provider service. We prepared a small plugin for that purpose, which works with WP Engine: wc-aelia-wpengine-geolocation.zip. The plugin doesn't require any configuration. Once uploaded and activated, it will automatically take the geolocation country and state from WP Engine.


14. The GeoIP database is outdated

This case is very rare, because our solutions update the GeoIP database automatically every week, but it can happen if the hosting provider prevents the replacement of the geolocation database file. You can verify this by connecting to your site via FTP. The GeoIP database file is called GeoLite2-City.mmdb and it's located in the wp-content/uploads/ folder. You can check the timestamp of the file to verify when it was last updated. 


If the file is more than one week old, it means that the file cannot be updated automatically. In this case, you can proceed as follows:

  1. Contact your hosting provider and ask them to set the wp-content/uploads folder as writable. This is required to be able to update the file.
  2. Using a plugin like WP Crontrol, open the list of scheduled task.
  3. Locate the task called aelia_afc_geoip_updater and run it.
    This will download the latest version of the GeoIP database.


After doing that, you can repeat the geolocation tests, which will return more accurate results.


 

Further reading


You can purchase the Currency Switcher from our online shop.