WC_Checkout::create_order_tax_lines()publicWC 1.0

Add tax lines to the order.

Method of the class: WC_Checkout{}

Return

null. Nothing (null).

Usage

$WC_Checkout = new WC_Checkout();
$WC_Checkout->create_order_tax_lines( $order, $cart );
$order(WC_Order) (required) (passed by reference — &)
Order instance.
$cart(WC_Cart) (required)
Cart instance.

WC_Checkout::create_order_tax_lines() code WC 8.6.1

public function create_order_tax_lines( &$order, $cart ) {
	foreach ( array_keys( $cart->get_cart_contents_taxes() + $cart->get_shipping_taxes() + $cart->get_fee_taxes() ) as $tax_rate_id ) {
		/**
		 * Controls the zero rate tax ID.
		 *
		 * An order item tax will not be created for this ID (which by default is 'zero-rated').
		 *
		 * @since 3.0.0 or earlier
		 *
		 * @param string $tax_rate_id The ID of the zero rate tax.
		 */
		if ( $tax_rate_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
			$item = new WC_Order_Item_Tax();
			$item->set_props(
				array(
					'rate_id'            => $tax_rate_id,
					'tax_total'          => $cart->get_tax_amount( $tax_rate_id ),
					'shipping_tax_total' => $cart->get_shipping_tax_amount( $tax_rate_id ),
					'rate_code'          => WC_Tax::get_rate_code( $tax_rate_id ),
					'label'              => WC_Tax::get_rate_label( $tax_rate_id ),
					'compound'           => WC_Tax::is_compound( $tax_rate_id ),
					'rate_percent'       => WC_Tax::get_rate_percent_value( $tax_rate_id ),
				)
			);

			/**
			 * Action hook to adjust item before save.
			 *
			 * @since 3.0.0
			 */
			do_action( 'woocommerce_checkout_create_order_tax_item', $item, $tax_rate_id, $order );

			// Add item to order and save.
			$order->add_item( $item );
		}
	}
}