使用 WC_Tax::get_tax_classes() 获取所有 WooCommerce 税级 [英] Using WC_Tax::get_tax_classes() to get all WooCommerce tax-classes

查看:47
本文介绍了使用 WC_Tax::get_tax_classes() 获取所有 WooCommerce 税级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的自定义插件中获取 Woocommerce 中的活动税级.当我使用 WC_Tax::get_tax_classes() 时,我得到一个空数组.

I try to get the active tax-classes in Woocommerce in my custom plugin. When I use the WC_Tax::get_tax_classes(), I get a empty array.

WC_tax 类如何在没有订单详细信息的情况下自行运行?

How does WC_tax class work without order details and run by itself?

推荐答案

WC_Tax::get_tax_classes() 当只有默认税种集时返回一个空数组在 WooCommerce >税收(标签)设置.

WC_Tax::get_tax_classes() returns an empty array when there is only the default tax class set in WooCommerce > Tax (tab) settings.

例如用于 wc_get_product_tax_class_options() 函数 显示管理产品页面设置中的可用税种:

It's used for example in wc_get_product_tax_class_options() function that displays the available tax classes in admin product pages settings:

/**
 * Get product tax class options.
 *
 * @since 3.0.0
 * @return array
 */
function wc_get_product_tax_class_options() {
    $tax_classes           = WC_Tax::get_tax_classes();
    $tax_class_options     = array();
    $tax_class_options[''] = __( 'Standard', 'woocommerce' );

    if ( ! empty( $tax_classes ) ) {
        foreach ( $tax_classes as $class ) {
            $tax_class_options[ sanitize_title( $class ) ] = $class;
        }
    }
    return $tax_class_options;
}

所以在使用 WC_Tax::get_tax_classes() 时,默认税类(活动税类)没有条目.

So the default tax class (active tax class) has no entry when using WC_Tax::get_tax_classes().

然后您可以使用 wc_get_product_tax_class_options() 函数来获取所有 WooCommerce 税类或来自此函数的代码,如果您想要更自定义的东西.

Then you can use wc_get_product_tax_class_options() function to get all WooCommerce tax classes or the code from this function if you want something more custom.

相关:如何获取可用WooCommerce 中的税率

这篇关于使用 WC_Tax::get_tax_classes() 获取所有 WooCommerce 税级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆