Php 如何删除商业中的特定国家/地区
有人能告诉我怎样才能从woocommerce中删除特定的国家吗。woocommerce中有一个选项,即销售地点与所有国家/地区和特定地区 然而,我想向所有国家销售,除了1个国家,例如美国!那我怎么才能把我们从国家名单上除名呢。如果我使用“特定国家”选项,那么我必须添加除美国以外的所有国家,这是一个较长的过程Php 如何删除商业中的特定国家/地区,php,wordpress,woocommerce,checkout,country,Php,Wordpress,Woocommerce,Checkout,Country,有人能告诉我怎样才能从woocommerce中删除特定的国家吗。woocommerce中有一个选项,即销售地点与所有国家/地区和特定地区 然而,我想向所有国家销售,除了1个国家,例如美国!那我怎么才能把我们从国家名单上除名呢。如果我使用“特定国家”选项,那么我必须添加除美国以外的所有国家,这是一个较长的过程 您是否有任何代码可以帮助我将其放入主题函数中,以便在结账时美国国家不会出现在国家列表中?请尝试以下代码片段 function woo_remove_specific_country( $co
您是否有任何代码可以帮助我将其放入主题函数中,以便在结账时美国国家不会出现在国家列表中?请尝试以下代码片段
function woo_remove_specific_country( $country )
{
unset($country["US"]);
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
参考文献
尝试以下代码片段
function woo_remove_specific_country( $country )
{
unset($country["US"]);
return $country;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
参考文献
如果您想保留一组国家,但您只有钥匙,请执行以下操作:
function woo_remove_specific_country( $countries ) {
global $woocommerce;
// default do not limit
$limited_countries = array_values(array_flip($countries));
// Country array to keep
$eu = $woocommerce->countries->get_european_union_countries( );
// keep countries, sort them out of the full array to keep the names
$found = array_filter($countries, function($item) use ($eu) {
return in_array($item, $eu);
}, ARRAY_FILTER_USE_KEY); // USE_KEY is essential cause we are filtering the language codes
// return the found countries
return $found;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
如果您想保留一系列国家,但您只有这些密钥,请执行以下操作:
function woo_remove_specific_country( $countries ) {
global $woocommerce;
// default do not limit
$limited_countries = array_values(array_flip($countries));
// Country array to keep
$eu = $woocommerce->countries->get_european_union_countries( );
// keep countries, sort them out of the full array to keep the names
$found = array_filter($countries, function($item) use ($eu) {
return in_array($item, $eu);
}, ARRAY_FILTER_USE_KEY); // USE_KEY is essential cause we are filtering the language codes
// return the found countries
return $found;
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
杰出的谢谢:)国家代码和姓名列表:太好了!谢谢:)国家代码和名称列表: