我使用的是针对欧盟国家的过滤器,效果很好。然而-我想包括英国,它不再是欧盟的一部分,以及美国。
有没有办法在WooCommerce中扩展get_european_union_countries()函数?那么我可以从WC_Countries获取一个特定的国家(英国、美国),这样我就可以在现有代码中将其添加到我的true语句中?
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;
});发布于 2021-09-30 06:56:26
除了使用现有代码之外,还可以使用woocommerce_european_union_countries筛选器挂钩
所以你会得到:
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 );https://stackoverflow.com/questions/69387137
复制相似问题