【问题标题】:Add a custom field value as a cart non taxable fee in Woocommerce在 Woocommerce 中添加自定义字段值作为购物车非应税费用
【发布时间】:2018-02-21 17:48:43
【问题描述】:

我在结帐中有一个自定义字段,可以将价格添加到购物车。

$woocommerce->cart->add_fee($price_info['label'], $fee, $taxable, $tax_class);

一切正常。但是我如何使它不征税?

【问题讨论】:

    标签: php wordpress woocommerce cart fee


    【解决方案1】:

    要使费用不征税,您需要将第三个参数设置为 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仍需纳税

    【讨论】:

    • 我想向购物车添加费用,但费用应显示为不含税,总计应含税
    • @melvin 所以你应该通过你的主题覆盖 woocommerce 模板。模板是cart/cart-totals.phpcheckout/review-order.php
    • 是否可以不覆盖但使用 woocommerce 的功能?
    • @melvin 我不这么认为……
    猜你喜欢
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 2022-01-22
    • 1970-01-01
    • 2016-01-14
    • 2018-06-30
    相关资源
    最近更新 更多