在Woocommerce中将自定义字段值添加为购物车的免税费用 [英] Add a custom field value as a cart non taxable fee in Woocommerce
本文介绍了在Woocommerce中将自定义字段值添加为购物车的免税费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在结帐时有一个自定义字段,为购物车增加了价格.
I have a custom field in checkout that adds a price to cart.
$woocommerce->cart->add_fee($price_info['label'], $fee, $taxable, $tax_class);
一切正常.但是我如何使其不征税?
Everything works fine. But how do i make it non taxable ?
推荐答案
要使费用免税,您需要将第3个参数设置为false,因此您的代码将是:
To make a fee non taxable you need to set the 3rd argument to false, so your code will be:
WC()->cart->add_fee( $price_info['label'], $fee );
第三个参数的默认值为false
,因此无需征税.查看其源代码:
The default value for the 3rd argument is false
, so no taxable. See its source code:
/**
* Add additional fee to the cart.
*
* @uses WC_Cart_Fees::add_fee
* @param string $name Unique name for the fee. Multiple fees of the same name cannot be added.
* @param float $amount Fee amount (do not enter negative amounts).
* @param bool $taxable Is the fee taxable? (default: false).
* @param string $tax_class The tax class for the fee if taxable. A blank string is standard tax class. (default: '').
*/
public function add_fee( $name, $amount, $taxable = false, $tax_class = '' ) {
$this->fees_api()->add_fee( array(
'name' => $name,
'amount' => (float) $amount,
'taxable' => $taxable,
'tax_class' => $tax_class,
) );
}
现在,如果您使用负费用(因此可以享受购物车折扣),即使将其设置为
false
,也应纳税.
Now if you use a negative fee (so a cart discount), it will be taxable even if you set it to
false
.
这篇关于在Woocommerce中将自定义字段值添加为购物车的免税费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文