【问题标题】:Remove countries in WooCommerce from an array of defined country codes从一系列定义的国家代码中删除 WooCommerce 中的国家
【发布时间】:2021-06-05 03:14:48
【问题描述】:

我找到了How to remove specific country in WooCommerce 答案代码,它适用于解除一个国家/地区的问题。如何使用它来取消设置更多国家/地区 3-4?

此代码可将美国从我的地理位置列表中隐藏。我需要它来隐藏更多基于国家代码“US”、“UK”、“RU”等的国家。我知道结帐可以从设置中完成,但我需要它来删除一些国家的地理定位插件默认情况下会显示所有国家/地区的列表以供选择。

【问题讨论】:

    标签: php wordpress woocommerce unset country-codes


    【解决方案1】:

    以下将从定义的国家代码数组中删除 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 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多