FOX - WooCommerce Currency Switcher Professional

Automatically Change Currency by Country in WooCommerce (GeoIP Rules)

To automatically change currency by country in WooCommerce, FOX uses GeoIP rules: you assign countries to each currency, and a visitor from Germany opens the shop in euros while a visitor from Canada sees Canadian dollars, without touching a switcher. The setup takes a few minutes. What surprises most shop owners afterwards is one design decision: the rules choose the currency on the visitor's first visit only. Below is how the whole chain works, how to set it up, how to test it correctly, and how to change the default behaviour when you need to.

How automatic currency by country works

Three steps run on the visitor's first page view:

  1. WooCommerce finds the country. FOX has no IP database of its own. It calls WC_Geolocation::geolocate_ip(), the same function WooCommerce uses for taxes and shipping. WooCommerce first reads a country header if the server or CDN sends one (for example CF-IPCountry from Cloudflare), then looks the IP address up in the MaxMind GeoLite2 database, and as a last resort asks a public lookup service.
  2. FOX matches the country. It walks through the country lists in its GeoIP tab. The first currency whose list contains the two-letter country code becomes the visitor's currency.
  3. FOX stores the result for this visitor, and every later page uses the stored currency.

Before the match, a brand-new visitor gets the Welcome currency from the Options tab. If the detected country is in one of your lists, the GeoIP currency replaces it on the same page view. If it is not, or if no country was detected, the visitor stays on the welcome currency. The browser language plays no role.

Set up automatic currency change by country

All FOX settings are in WooCommerce → Settings → Currency.

  1. Add every currency you want to show in the Currencies tab. FOX does not translate a country into its local currency by itself: a visitor can only get a currency that exists in your list and has their country assigned. A shop with EUR, GBP and USD can serve the whole world, but a Japanese visitor sees yen only if you add JPY.
  2. Give WooCommerce a country source. Create a free MaxMind account, generate a key and save it in WooCommerce → Settings → Integration → MaxMind Geolocation; WooCommerce downloads the database when the key is saved. The WooCommerce MaxMind guide shows the steps. Set Default customer location in WooCommerce → Settings → General to a Geolocate option, so that WooCommerce itself works with the same country for taxes, shipping and the pre-filled checkout address.
  3. Assign countries in the GeoIP tab of FOX. Each currency has a multi-select list with Select all and Clear all buttons. The tab appears when WooCommerce is active, because the rules depend on its geolocation class.
  4. Choose the welcome currency in the Options tab. It is what visitors from all unlisted countries get, so it works as "everyone else". Use a currency that is visible in the switcher; the option's own description warns against a hidden one.
  5. Press Save changes.

A typical configuration for a shop based in the eurozone:

CurrencyCountries in its GeoIP listWho gets it on the first visit
EURthe euro-area countriesvisitors from those countries
GBPUnited KingdomBritish visitors
CHFSwitzerland, LiechtensteinSwiss and Liechtenstein visitors
USD (welcome currency)emptyeveryone else, and visitors whose country could not be detected

Three rules decide the edge cases. A country listed under two currencies goes to the first one in the order of the Currencies tab. A country that is in no list gets the welcome currency. Adding a market to your shipping zones does not add it to the GeoIP rules; add it here as well.

Country profiles

Below the rules, GeoIP profiles let you save a named set of countries and apply it with Add to: and a currency. Applying a profile replaces that currency's list with the profile's countries; it does not append to it. FOX ships with an EU countries profile, which lists EU member states, not the euro area, so it includes countries with their own currencies, such as Sweden, Czechia, Denmark, Hungary and Romania. After applying it to EUR, remove the countries you want to serve in another currency and check the list before saving.

Why the currency changes only on the first visit

The GeoIP rules decide what a visitor sees first, not what they are stuck with. Once FOX has stored a currency for a visitor, it uses that currency on every page, so a visitor who prefers dollars can switch and keep dollars. The same mechanism explains the reports that "GeoIP stopped working": your own browser already has a stored currency, and changing the rules does not touch visitors who already have one.

What counts as a new visitor depends on Currency storage in the Options tab:

Currency storageThe visitor is identified byA new visit is
PHP Sessionthe PHP session cookie of the browsera new browser or device, or a new session
FOX Sessiona wp_woocs_session_ cookie that lives 48 hoursa new browser or device, or the cookie expired
Transient, Memcached, Redisthe IP addressa new network; every device on one Wi-Fi counts as one visitor

So a customer who travels gets the currency of the new country again with IP-based storage, but keeps their old currency with a session storage. Changing the storage type also throws away all stored currencies, which is why GeoIP sometimes seems to "start working" right after that change: every visitor is new once.

Test it as a new visitor

Testing in the browser you used to set up the shop shows your stored currency, not the GeoIP result. Do this instead:

  1. Put [woocs_geo_hello] [woocs_show_current_currency] on a draft page and exclude that page from every cache. [woocs_geo_hello] prints the country WooCommerce detects for you, [woocs_show_current_currency] the currency FOX uses for you.
  2. With PHP Session or FOX Session, open the page in a private window that has not visited the site yet.
  3. With Transient, Memcached or Redis, a private window is not enough, because the IP address is the same. Use another connection, for example a phone on mobile data, or a VPN that is switched on before the site is opened and whose address nobody has used for a test.

VPN addresses are not always located where the provider says, so trust the country printed by [woocs_geo_hello]. If that country is missing or wrong, or the country is right but the currency is not, follow the troubleshooting checklist in WooCommerce geolocation shows the wrong currency. If the shop pages are cached, read why a currency switcher and a page cache fight each other before going live: a cached page was built for another visitor, and the GeoIP decision runs in PHP.

Turn automatic switching off, or make it permanent

No automatic switching

There is no separate on/off switch: GeoIP is active whenever a currency has countries assigned. Press Clear all for every currency in the GeoIP tab and save. Every new visitor then starts with the welcome currency and changes it only with a switcher.

The country's currency on every page

Some shops must not let visitors from a listed country browse in another currency. The snippet below re-applies the GeoIP currency on every page view, after FOX has detected the country:

/*
 * FOX: always show the currency assigned to the visitor's country
 * in the GeoIP tab. Visitors from unlisted countries can still switch.
 * Child theme functions.php or a code snippets plugin.
 */
add_action('wp_head', function () {
    global $WOOCS;
    if (empty($WOOCS)) {
        return;
    }
    // Two-letter country code stored by FOX, for example "DE"
    $country  = $WOOCS->storage->get_val('woocs_user_country');
    $currency = $WOOCS->get_currency_by_country($country);
    if ($currency && $currency !== $WOOCS->current_currency) {
        $WOOCS->set_currency($currency);
    }
}, 1000);

Priority 1000 runs it after FOX's own wp_head code, which stores the country. It reads your GeoIP lists through $WOOCS->get_currency_by_country(), so the rules stay in one place. If you write your own country logic instead, compare real country codes: WooCommerce returns FR, ES or IT, never EU, so a condition like 'EU' == $country never matches. If Is multiple allowed in the Advanced tab is No, the checkout is charged in the base currency; then start the function with if (is_checkout()) { return; } so the checkout page does not mix the two. Like every PHP decision, the snippet does not run for a page served from a full page cache.

No switcher at all

Automatic detection does not need a visible switcher. Do not place the [woocs] shortcode or the widget, and keep the side switcher off in the Side tab; visitors simply get the currency of their country. If you do show a switcher, the floating side currency switcher needs no theme changes.

Prices, checkout and the billing country

GeoIP rules choose the currency; the price is the base price converted at your exchange rate. To set your own price for a market, for example 45 euros instead of a converted 45.37, see WooCommerce price based on country. Whether the customer then pays in the GeoIP currency or in your base currency is a separate decision, explained in show prices in local currency, charge in base currency.

The IP address tells you where the connection comes from, not where the customer lives. When the payment currency must match the address the customer enters at checkout, use checkout currency based on the customer's country on top of, or instead of, the GeoIP rules.

Checklist

  • Every currency you want to show exists in the Currencies tab.
  • WooCommerce can locate visitors: MaxMind key saved, or a country header from your CDN.
  • Each target country is in exactly one GeoIP list; the welcome currency covers everyone else.
  • Tested as a new visitor for your storage type, on an uncached page with [woocs_geo_hello].
  • Page cache configured for currencies if the shop pages are cached.

If a brand-new visitor from a listed country still gets the wrong currency with caches disabled, open a topic on the FOX support forum with a link to your test page, your GeoIP rules and your storage setting, and we will look at it.