Important

This article refers to the Currency Switcher for Easy Digital Downloads. That plugin was retired in 2021 and it's no longer available for purchase. If you're looking for the documentation for the Aelia Currency Switcher for WooCommerce, please refer to the following article: https://aelia.freshdesk.com/a/solutions/articles/3000010676.

The code in this article is 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 will check for a selected currency during the wordpress_loaded event. To force the selected currency to a specific one, set the value of $POST ["aelia_cs_currency"] in a hook attached to wordpress_loaded event. The hook must have a priority of 0 (zero), as the Currency Switcher will run its own with a priority of 1.


Examples

To use the code in the examples, simply place it in your theme's functions.php. See How to Safely Add Custom Code to WordPress Sites for more information on how to do that.


Example 1 - Forcing currency to USD 

add_filter('edd_aelia_cs_selected_currency', function($selected_currency) {
  // Force the selected currency to US Dollars
  $selected_currency = 'USD';
  return $selected_currency;
}, 10, 1);

 

Example 2 - Selecting the currency depending on the active language

This example is designed to work with WPML, you might have to adapt it to other multi-language plugins.       

function aelia_set_currency_by_language() {
  // Only change the currency on the frontend
  if(!is_admin() || defined('DOING_AJAX')) {
    // Select EUR when the language is German, USD otherwise
    if(defined('ICL_LANGUAGE_CODE') && (ICL_LANGUAGE_CODE === 'de')) {
      $_POST['aelia_cs_currency'] = 'EUR';
    }
    else {
      $_POST['aelia_cs_currency'] = 'USD';
    }  
  }
}
add_action('init', 'aelia_set_currency_by_language', 0);


You can purchase the Currency Switcher from our online shop.