【问题标题】:How to remove specific country in WooCommerce如何在 WooCommerce 中删除特定国家
【发布时间】:2016-06-01 12:25:05
【问题描述】:

谁能告诉我如何从 woocommerce 中删除特定国家/地区。 woocommerce 中有一个选项表示销售地点与所有国家和特定国家。

但是,我想向除 1 个国家(例如美国)以外的所有国家/地区销售产品!那么如何从国家列表中删除美国。就好像我使用“特定国家”选项一样,我将不得不添加除美国以外的所有国家,这是较长的过程。

您有什么代码可以帮助我,我可以将其放入主题的功能中,以便在结帐时美国国家不会出现在国家/地区列表中?

【问题讨论】:

    标签: php wordpress woocommerce checkout country


    【解决方案1】:

    试试下面这个sn-p

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

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

    【讨论】:

    【解决方案2】:

    如果您想保留一系列国家/地区,但您只有密钥,请执行以下操作:

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

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 2021-06-05
      • 2018-12-03
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 2018-07-23
      相关资源
      最近更新 更多