Advertisement
businessdad

Multilingualpress - Set currency by language

Jan 12th, 2020
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. /**
  2.  * Sets the currency depending on the active language in Multilingualpress.
  3.  *
  4.  * DISCLAIMER
  5.  * Aelia and any member of its staff are not responsible for any data loss or damage incurred
  6.  * when using the code, which you can use at your own risk.
  7.  *
  8.  * GPL DISCLAIMER
  9.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  10.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  11.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  12.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  13.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  14.  *
  15.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  16.  */
  17. function set_currency_by_language() {
  18.   // Only change the currency on the frontend
  19.   if(!is_admin() || defined('DOING_AJAX')) {
  20.     // Map each language to a currency
  21.     $language_currency_map = array(
  22.       'en' => 'GBP',
  23.       'no' => 'NOK',
  24.       'da' => 'DKK',
  25.     );
  26.  
  27.     $current_language = function_exists('mlp_get_current_blog_language') ? mlp_get_current_blog_language(true) : '';
  28.  
  29.     if(isset($language_currency_map[$current_language])) {
  30.       $_POST['aelia_cs_currency'] = $language_currency_map[$current_language];
  31.     }
  32.     else {
  33.       // Default: GBP
  34.       $_POST['aelia_cs_currency'] = 'GBP';
  35.     }
  36.   }
  37. }
  38. add_action('woocommerce_init', 'set_currency_by_language', 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement