I'm using a filter that targets the EU countries, which works well. However - I would like to included UK which isn't part of the EU anymore as well as US.
Is there a way to extend get_european_union_countries() function in WooCommerce? So I get a specific country (UK, US) from WC_Countries, so I can add it to my true
statement in my existing code?
add_filter( 'wc_aelia_tdbc_keep_prices_fixed', function($keep_prices_fixed): bool {
$countries = new WC_Countries();
$eu_countries = $countries->get_european_union_countries();
if ( WC()->customer ) {
if ( in_array( WC()->customer->get_billing_country(), $eu_countries ) ) {
$keep_prices_fixed = true;
} else {
$keep_prices_fixed = false;
}
}
return $keep_prices_fixed;
});
CodePudding user response:
Besides using your existing code you can use the woocommerce_european_union_countries
filter hook
So you get:
function filter_woocommerce_european_union_countries( $countries, $type ) {
// Add to the array
array_push( $countries, 'UK', 'US' );
return $countries;
}
add_filter( 'woocommerce_european_union_countries', 'filter_woocommerce_european_union_countries', 10, 2 );