How to remove specific country in WooCommerce

强颜欢笑 提交于 2019-12-04 21:06:09

Try this following snippet

function woo_remove_specific_country( $country ) 
{
   unset($country["US"]);
   return $country; 
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );

Reference http://www.boopathirajan.com/remove-specific-country-woocommerce-country-list/

If you want to keep an array of countries, but you only have the keys, do something like this:

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 );

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!