问题描述
我发现 How to remove specific country in WooCommerce 答案代码可用于取消设置一个国家/地区。如何使用它来取消设置更多国家/地区 3-4?
此代码用于在我的地理位置列表中隐藏美国。我需要它根据国家/地区代码“US”、“UK”、“RU”等隐藏更多国家。我知道可以从设置中完成结帐,但我需要它删除一些国家/地区的地理定位插件默认情况下会显示可供选择的所有国家/地区的列表。
解决方法
以下内容将从一组已定义的国家/地区代码中删除 WooCommerce 中的国家/地区:
add_filter( 'woocommerce_countries','woo_remove_countries' );
function woo_remove_countries( $countries ) {
// Here set in the array the country codes you from countries you want to remove
$countries_to_remove = array('US','GB','RU');
foreach ( $countries_to_remove as $country_code ) {
unset($countries[$country_code]);
}
return $countries;
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经测试有效。