Title: Multi currency language issue
Last modified: September 1, 2016

---

# Multi currency language issue

 *  Resolved [rannveigha1](https://wordpress.org/support/users/rannveigha1/)
 * (@rannveigha1)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/)
 * Hi thanks for this great plugin!
 * I am having a slight issue with the multi currency feature based on language 
   change using the qTranslate X plugin. I implemented the following code as suggested
   in previous support threads but the add_action is throwing an error in my function.
   php file. I cannot access the wp-admin page when using the add_action but when
   I change it to add_shortcode I can access the page but the currency doesn’t change
   according to language change. Any idea how I can fix this so the currency changes
   according to the language and my site doesn’t break?
 * Here is the code I am using:
 *     ```
       function qtranx_setCountry(){
       	$lang = qtranxf_getLanguage();
       	if ( $lang == 'en'){
       		WC()->customer->set_country('US');
       	} else{
       		WC()->customer->set_country('IS');
       	}
       }
       add_action( 'woocommerce_init', 'qtranx_setCountry' );
       ```
   
 * But I changed it to:
 *     ```
       function qtranx_setCountry(){
       	$lang = qtranxf_getLanguage();
       	if ( $lang == 'en'){
       		WC()->customer->set_country('US');
       	} else{
       		WC()->customer->set_country('IS');
       	}
       }
       add_shortcode( 'woocommerce_init', 'qtranx_setCountry' );
       ```
   
 * Best regards!
 * [https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [John Clause](https://wordpress.org/support/users/johnclause/)
 * (@johnclause)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568373)
 * There is plugin [WooCommerce Product Price Based on Countries](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/),
   which may do what you need.
 * ‘woocommerce_init’ is action, not a shortcut. The latter will not work work for
   you. Try to troubleshoot the error message you get, as it should work.
 * The only problem might be timing. qtranx_setCountry must be executed after language
   is detected in action ‘plugins_loaded’. I am not sure when ‘woocommerce_init’
   is executed – investigate it.
 *  Thread Starter [rannveigha1](https://wordpress.org/support/users/rannveigha1/)
 * (@rannveigha1)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568379)
 * Hi John and thanks for your reply 🙂
 * I am already using this plugin and using the previous mentioned code from the
   plugin author as he wrote it in this thread [here](https://wordpress.org/support/topic/sync-with-qtranslate-x?replies=3).
 * As far as I can see the qtranx_setCountry function is executed after the language
   is detected as it is at the bottom of my function.php file. The frontend of my
   website seems to be working fine when I use the add_action code block but the
   backend is broken an throwing a HTTP 500 error.
 * Any other ideas as to why this is and how I can fix it?
 * P.s. I am using the Oxygen theme by Laborator if that makes any difference
 *  Plugin Author [Oscar Gare](https://wordpress.org/support/users/oscargare/)
 * (@oscargare)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568380)
 * Hi, try this:
 *     ```
       if ( ! is_admin() ) {
       	function qtranx_setCountry(){
       		$lang = qtranxf_getLanguage();
       		if ( $lang == 'en'){
       			WC()->customer->set_country('US');
       		} else{
       			WC()->customer->set_country('IS');
       		}
       	}
       	add_action( 'woocommerce_init', 'qtranx_setCountry' );
       }
       ```
   
 *  [John Clause](https://wordpress.org/support/users/johnclause/)
 * (@johnclause)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568381)
 * This code should probably be executed at front end only? Position of code within
   functions.php should not make difference in that regard, but filter/action within
   which it gets executed matters.
 * 500 errors are normally easy to debug, since there is a clear error message in
   error_log, which you should lookup before bringing it into the discussion. It
   probably crashes because WC()->customer is not defined at admin side.
 * You have to find a right filter/action to execute this code within. Did you investigate
   when ‘woocommerce_init’ is firing? It probably gets executed in the very beginning
   at both front and admin, but you need front only.
 * Maybe ask Woocommerce which filter they would recommend for such purpose. Or 
   read their docs, I am sure it is somewhere there. Or simply investigate it yourselves,
   or hire a developer with PHP skills to do it, if you do not wish to spend time
   on this.
 * I guess, I got on this thread by accident, mixing it up with other thread, sorry
   for the intrusion. Good luck to you to figure it out rather sooner!
 * P.S. In fact, I have just realized that making country to depend on language 
   is probably not a good idea in general, since people speak any language in any
   country. You cannot assume that if a person speaks English, then they live in
   England 🙂 I would use a different method to set the country. Those are my two
   cents 🙂
 *  Thread Starter [rannveigha1](https://wordpress.org/support/users/rannveigha1/)
 * (@rannveigha1)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568383)
 * Thank you both for your input 🙂
 * The code worked oscargare, everything is working as it should now. Thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Multi currency language issue’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-product-price-based-on-countries/assets/icon-
   256x256.png?rev=1976858)
 * [Price Based on Country for WooCommerce](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/reviews/)

## Tags

 * [multi currency](https://wordpress.org/support/topic-tag/multi-currency/)
 * [multi-language](https://wordpress.org/support/topic-tag/multi-language/)

 * 5 replies
 * 3 participants
 * Last reply from: [rannveigha1](https://wordpress.org/support/users/rannveigha1/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/multi-currency-language-issue/#post-7568383)
 * Status: resolved