WC_Abstract_Legacy_Order::add_tax()
Add a tax row to the order.
Method of the class: WC_Abstract_Legacy_Order{}
No Hooks.
Return
Int
. order item ID
Usage
$WC_Abstract_Legacy_Order = new WC_Abstract_Legacy_Order(); $WC_Abstract_Legacy_Order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
- $tax_rate_id(int) (required)
- -
- $tax_amount(int)
- amount of tax.
- $shipping_tax_amount(int)
- shipping amount.
WC_Abstract_Legacy_Order::add_tax() WC Abstract Legacy Order::add tax code WC 9.7.1
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(); }