I am using WooCommerce with WooCommerce Multilingual. So I am using different currencies. I want to unset billing and shipping countries based on the current active currency.
I found this function to unset countries:
function woo_remove_specific_country( $country ) {
unset($country["US"]);
unset($country["GB"]);
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
But I want to change this function so there is conditional logic in it. So for example when EUR
is the active current currency US
and GB
has to be the unset countries. If GBP
is the current active currency only US
needs to be unset.
So I found this to get the current active currency:
$currency = get_woocommerce_currency();
When using this to test it inside a shortcode it gives me the right active currency.
So I rewrote the function:
function woo_remove_specific_country( $country ) {
$currency = get_woocommerce_currency();
if ($currency == 'EUR') {
unset($country["US"]);
unset($country["GB"]);
}
if ($currency == 'GBP') {
unset($country["US"]);
}
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
But this doesn't work. It looks like it always takes the way of the if with EUR
while my currency is GBP
at that moment.