2

我正在经营一家 WooCommerce v. 3 商店并使用支付插件“Quickpay”。支付插件支持将交易费用添加到订单中,这很棒,但它是在我 WooCommerce 的订单中添加的,不含税。

我找到了设置交易费用的代码。我已经尝试通过 WC 的文档进行挖掘,但仍然无法弄清楚。

任何人都可以帮我设置它,以便为交易费用计算税金吗?

这是当前代码:

    /**
     * add_transaction_fee function.
     *
     * Adds order transaction fee to the order before sending out the order confirmation
     *
     * @access   public
     *
     * @param $fee_amount
     *
     * @return bool
     */

    public function add_transaction_fee($fee_amount)
    {
        if ($fee_amount > 0) {
            $amount = $fee_amount / 100;
            $fee = (object) array(
                'name' => __('Payment Fee', 'woo-quickpay'),
                'amount' => wc_format_decimal($amount),
                'taxable' => FALSE,
                'tax_class' => NULL,
                'tax_data' => array(),
                'tax' => 0,
            );

            if (version_compare( WC_VERSION, '3.0', '<' )) {
                $this->add_fee($fee);
            } else {

	            $item = new WC_Order_Item_Fee();
	            $item->set_props( array(
		            'name'      => $fee->name,
		            'tax_class' => $fee->tax_class,
		            'total'     => $amount,
		            'total_tax' => 0,
		            'order_id'  => $this->get_id(),
	            ) );
	            $item->save();
	            $this->add_item( $item );
            }

            $this->set_total( $this->get_total() + $amount );

            return TRUE;
        }
        return FALSE;
    }

4

0 回答 0