WC_Abstract_Legacy_Order::add_tax( int $tax_rate_id, int $tax_amount, int $shipping_tax_amount )

Add a tax row to the order.


Description Description


Parameters Parameters

$tax_rate_id

(Required)

$tax_amount

(Required) amount of tax.

$shipping_tax_amount

(Required) shipping amount.


Top ↑

Return Return

(int) order item ID


Top ↑

Source Source

File: includes/legacy/abstract-wc-legacy-order.php

	public function add_tax( $tax_rate_id, $tax_amount = 0, $shipping_tax_amount = 0 ) {
		wc_deprecated_function( 'WC_Order::add_tax', '3.0', 'a new WC_Order_Item_Tax object and add to order with WC_Order::add_item()' );

		$item = new WC_Order_Item_Tax();
		$item->set_props( array(
			'rate_id'            => $tax_rate_id,
			'tax_total'          => $tax_amount,
			'shipping_tax_total' => $shipping_tax_amount,
		) );
		$item->set_rate( $tax_rate_id );
		$item->set_order_id( $this->get_id() );
		$item->save();
		$this->add_item( $item );
		wc_do_deprecated_action( 'woocommerce_order_add_tax', array( $this->get_id(), $item->get_id(), $tax_rate_id, $tax_amount, $shipping_tax_amount ), '3.0', 'woocommerce_new_order_item action instead.' );
		return $item->get_id();
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.