The code in this article is to be considered a customisation. As such, it's outside the scope of our support service. Should you need assistance implementing the code, please feel free to contact us to request a consultation.


The Currency Switcher contains an extensive list of currencies, and an association between a country and the currency used in it. For example, all 

countries in the Eurozone are associated to Euro, with the exception of United Kingdom, Sweden, Norway, Denmark and a few others. Depending on your setup, you may need to ensure that visitors from a country see prices in a specific currency, which may not match the one set by default in the Currency Switcher.


How to modify the default country/currency association list

You can change the currency associated with each country by implementing a custom filter. Below you can find a sample filter, which you can copy and adapt to your needs.  

add_filter('wc_aelia_currencyswitcher_country_currencies', function($country_currencies) {
  // To change the currency associated to a country, copy the following line,
  // changing the placeholder for country and currency code
  //$country_currencies['<country code>'] = '<currency code>';

  // Examples
  // Set currency to Euro for Denmark, Finland, Norway, Sweden, Switzerland and Great Britain
  $country_currencies['DK'] = 'EUR';
  $country_currencies['FI'] = 'EUR';
  $country_currencies['NO'] = 'EUR';
  $country_currencies['SE'] = 'EUR';
  $country_currencies['CH'] = 'EUR';
  $country_currencies['GB'] = 'EUR';

  return $country_currencies;
}, 10, 1);

  

How to use the code

You can use the code in several ways:


1. Wrap the custom code into a small custom plugin
The advantage of using a custom plugin is that the code is going to be loaded very early. This will prevent issues that can happen when the theme's functions are loaded too late. Below you can find a template of the plugin, including the same custom code you can find above. To use it, you can follow these simple steps:

  1. Download the template plugin.
  2. Edit file wc-aelia-cs-change-country-currencies.php, altering the association of countries and currencies.
  3. Save the file.
  4. Upload and activate the plugin on your site. No configuration is needed, the custom code will load automatically.


2. Add it to your theme's functions.php file

After you add the code to your theme, it will be executed automatically at the next page load.

Important: this approach is no longer recommended, as the functions.php file could be loaded too late, and the custom country/currency association might not be taken into account during geolocation. In such case, using the other approaches, provided above, is a better solution.


Should you have any questions, please feel free to contact us. We are always happy to answer any questions you might have.


You can purchase the Currency Switcher from our online shop.