Advertisement
businessdad

WooCommerce Currency Switcher - Set currency by language

Dec 12th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. /**
  2.  * Sets the currency depending on the language selected via WPML.
  3.  *
  4.  * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_aelia
  5.  *
  6.  * @author Aelia
  7.  * @link https://aelia.co
  8.  */
  9. function aelia_set_currency_by_language() {
  10.   // If no languague was selected, don't do anything
  11.   if(!defined('ICL_LANGUAGE_CODE')) {
  12.     return;
  13.   }
  14.  
  15.   // Map each language with the appropriate currency
  16.   $currencies_by_language = array(
  17.     'de' => 'EUR',
  18.     'pt' => 'EUR',
  19.     'sv' => 'SEK',
  20.     // Etc etc
  21.   );
  22.  
  23.   // Only change the currency on the frontend, depending on the language
  24.   if((!is_admin() || defined('DOING_AJAX')) && isset($currencies_by_language[ICL_LANGUAGE_CODE])) {
  25.     $_POST['aelia_cs_currency'] = $currencies_by_language[ICL_LANGUAGE_CODE];
  26.   }
  27. }
  28. add_action('woocommerce_init', 'aelia_set_currency_by_language', 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement