首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WooCommerce中扩展get_european_union_countries()函数

在WooCommerce中扩展get_european_union_countries()函数
EN

Stack Overflow用户
提问于 2021-09-30 06:23:40
回答 1查看 48关注 0票数 1

我使用的是针对欧盟国家的过滤器,效果很好。然而-我想包括英国,它不再是欧盟的一部分,以及美国。

有没有办法在WooCommerce中扩展get_european_union_countries()函数?那么我可以从WC_Countries获取一个特定的国家(英国、美国),这样我就可以在现有代码中将其添加到我的true语句中?

代码语言:javascript
复制
add_filter( 'wc_aelia_tdbc_keep_prices_fixed', function($keep_prices_fixed): bool {        
    $countries = new WC_Countries();
    $eu_countries = $countries->get_european_union_countries();

    if ( WC()->customer ) {
       if ( in_array( WC()->customer->get_billing_country(), $eu_countries ) ) {
            $keep_prices_fixed = true;
        } else {
            $keep_prices_fixed = false;
        }
    }

    return $keep_prices_fixed;
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-30 06:56:26

除了使用现有代码之外,还可以使用woocommerce_european_union_countries筛选器挂钩

所以你会得到:

代码语言:javascript
复制
function filter_woocommerce_european_union_countries( $countries, $type ) { 
    // Add to the array
    array_push( $countries, 'UK', 'US' );
    
    return $countries;
}
add_filter( 'woocommerce_european_union_countries', 'filter_woocommerce_european_union_countries', 10, 2 );
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69387137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档