Php 在Woocommerce中添加自定义字段值作为购物车非应税费用
我在结帐时有一个自定义字段,用于向购物车添加价格Php 在Woocommerce中添加自定义字段值作为购物车非应税费用,php,wordpress,woocommerce,cart,fee,Php,Wordpress,Woocommerce,Cart,Fee,我在结帐时有一个自定义字段,用于向购物车添加价格 $woocommerce->cart->add_fee($price_info['label'], $fee, $taxable, $tax_class); 一切正常。但是如何使其不纳税?要使费用不纳税,您需要将第3个参数设置为false,因此您的代码为: WC()->cart->add_fee( $price_info['label'], $fee ); 第三个参数的默认值是false,因此不需要任何参数。请参阅其源
$woocommerce->cart->add_fee($price_info['label'], $fee, $taxable, $tax_class);
一切正常。但是如何使其不纳税?要使费用不纳税,您需要将第3个参数设置为false,因此您的代码为:
WC()->cart->add_fee( $price_info['label'], $fee );
第三个参数的默认值是false
,因此不需要任何参数。请参阅其源代码:
/**
* 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
,也应纳税
我想将费用添加到购物车,但费用应显示为不含税,合计应为tax@melvin因此,您应该通过您的主题覆盖woocommerce模板。模板是
cart/cart totals.php
和结帐/审核订单。php
是否可以不重写而使用woocommerce的函数?@melvin我不这么认为…