php - 使用 WC_Tax::get_tax_classes() 获取所有 WooCommerce 税级

标签 php wordpress methods woocommerce tax

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

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

最佳答案

当 WooCommerce > 税中仅设置默认税级时,

WC_Tax::get_tax_classes() 返回空数组(选项卡)设置。

它用于例如 wc_get_product_tax_class_options() function在管理产品页面设置中显示可用的税级:

/**
 * 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() 时,默认税级(有效税级)没有条目。

然后,您可以使用 wc_get_product_tax_class_options() 函数获取所有 WooCommerce 税类,或者如果您想要更自定义的内容,则可以使用此函数的代码。

相关:How to get the available tax rates in WooCommerce

关于php - 使用 WC_Tax::get_tax_classes() 获取所有 WooCommerce 税级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66196547/

相关文章:

php - 使用 like 和通配符过滤集合

php - 在 PHP 中使用单个 header() 调用发送多个 HTTP header

php - 将内爆数据与另一个内爆进行匹配

python - [Python]调用方法(self)

java - 计算现有对象的数量

java - 调用方法时找不到符号

php - 在php中使用一个文件进行数据连接

javascript - 是否可以创建嵌入式 React 应用程序小部件?

css - 我无法删除 ?author=AND url 到 Wordpress 中的昵称

php - 从 PHP 和 Timber/Twig 中的高级自定义字段对转发器字段进行排序