首页 > 解决方案 > 在 Woocommerce 3+ 中检查产品价格是否含税

问题描述

如何以编程方式检查产品价格是否包含税费?我检查了 WC_Product 参考,但找不到类似的东西。

标签: phpwordpresswoocommercepricetax

解决方案


您只需wc_prices_include_tax()IF语句中使用专用的条件函数:

if( wc_prices_include_tax() ) {
    // Price include tax
} else {
    // Price doesn't include tax
}

它将检查是否在 Woocommerce 中启用了税费,以及您的产品价格常规设置是否包含税费。

例如wc_prices_include_tax()wc_get_price_including_tax()价格WC_Product函数(不是方法)wc_get_price_to_display()使用,当需要在产品页面中显示产品价格(包括税费)时 ,在价格函数中使用自己......</p>

如果需要在产品页面中显示不含税的产品价格,wc_get_price_to_display()将使用wc_get_price_excluding_tax()

wc_get_price_to_display(),wc_get_price_including_tax()wc_get_price_excluding_tax()有 2 个参数:

$product (强制)WC_Product对象
$args (可选)包含产品价格和数量的数组

相关:显示含税和不含税的 Woocommerce 产品价格和税额


在购物车、结帐和订单上,还有另一个常规设置,可让您显示含税或不含税的价格。您可以使用以下方法检查显示的价格是否含税:

if( get_option( 'woocommerce_tax_display_cart' ) ) {
    // Prices displayed including tax
}

订购物品相关:


推荐阅读