php - 在 Woocommerce 3+ 中检查产品价格是否含税
问题描述
如何以编程方式检查产品价格是否包含税费?我检查了 WC_Product 参考,但找不到类似的东西。
解决方案
您只需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
}
订购物品相关:
推荐阅读
- laravel - Laravel 自定义密码邮箱
- sql - 查询内的多个替换
- python - 使用 Flask 从提交的 HTML 表单值重定向链接
- android - appcompat-v7:28.0.0-rc02 不适用于 design:28.0.0-rc01(应该是 rc02,但我们不能)
- android - 从 PHP 服务器获取 JSON 数据
- ignite - 阿帕奇点燃 | TCP 发现 SPI
- python - 使用 PYTHON 和 JSON 传递 API 页面
- ios - UITextView 中的 UITextField 函数不可用
- python - 从 Selenium 导入元素时,会写入 CSV 上的多行而不是一行
- kotlin - 如何在 Kotlin 中分配当前类实例