You must change customer country in “woocommerce_init” action throught WC->customer->set_country
Can you tell me from where I must do this? I can`t find it?
Hi! you can try something like this:
function qtranx_setCountry(){
$lang = qtranxf_getLanguage();
if ( $lang == 'en'){
WC()->customer->set_country('US');
} else{
WC()->customer->set_country('CA');
}
}
add_action( 'woocommerce_init', 'qtranx_setCountry' );
In which file i must put this? Thank you.
You can add this code in the functions.php file of your active theme.
Thank you. Everything is fine now. :))
Hello oscargare,
I have a shop with 2 currencies (EUR, HUF), from Hungary people pay with HUF, from other countries of Europa with EUR, how to change the example function to use like this?
try this:
function qtranx_setCountry(){
$lang = qtranxf_getLanguage();
if ( $lang == 'hu'){
WC()->customer->set_country('HU');
} else{
WC()->customer->set_country('DE');
}
}
add_action( 'woocommerce_init', 'qtranx_setCountry' );
See
https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
If you like my plugin please leave me a 5 stars rating.
Thank you.
Hi oscargare
I wish to show DKK when danish is selected as language and EUR for english (all other countries than Denmark). I tried adding the code
function qtranx_setCountry(){
$lang = qtranxf_getLanguage();
if ( $lang == 'en'){
WC()->customer->set_country('US');
} else{
WC()->customer->set_country('DA');
}
}
add_action( 'woocommerce_init', 'qtranx_setCountry' );
However, nothing happens on http://helgstranddenmark.com/da/shop/ when changing language and wp-admin shows the following error:
“Fatal Error: Call to a member function set country() on a non-object in /home/helgstr1/public_html/wp-content/themes/gt3-wp-frame/functions.php on line 933”
I also tried putting “da” first, but that didn’t work either.
Can you help?
Hi Oscargare
Thank you so much. Works perfectly now!
I’ll give your plugin 5 stars.