/**
* Sets the currency depending on the language selected via WPML.
*
* Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_aelia
*
* @author Aelia
* @link https://aelia.co
*/
function aelia_set_currency_by_language() {
// If no languague was selected, don't do anything
if(!defined('ICL_LANGUAGE_CODE')) {
return;
}
// Map each language with the appropriate currency
$currencies_by_language = array(
'de' => 'EUR',
'pt' => 'EUR',
'sv' => 'SEK',
// Etc etc
);
// Only change the currency on the frontend, depending on the language
if((!is_admin() || defined('DOING_AJAX')) && isset($currencies_by_language[ICL_LANGUAGE_CODE])) {
$_POST['aelia_cs_currency'] = $currencies_by_language[ICL_LANGUAGE_CODE];
}
}
add_action('woocommerce_init', 'aelia_set_currency_by_language', 0);
Comments