WC_Checkout::create_order_fee_lines()publicWC 1.0

Add fees to the order.

Метод класса: WC_Checkout{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

$WC_Checkout = new WC_Checkout();
$WC_Checkout->create_order_fee_lines( $order, $cart );
$order(WC_Order) (обязательный) (передается по ссылке — &)
Order instance.
$cart(WC_Cart) (обязательный)
Cart instance.

Код WC_Checkout::create_order_fee_lines() WC 8.7.0

public function create_order_fee_lines( &$order, $cart ) {
	foreach ( $cart->get_fees() as $fee_key => $fee ) {
		$item                 = new WC_Order_Item_Fee();
		$item->legacy_fee     = $fee; // @deprecated 4.4.0 For legacy actions.
		$item->legacy_fee_key = $fee_key; // @deprecated 4.4.0 For legacy actions.
		$item->set_props(
			array(
				'name'      => $fee->name,
				'tax_class' => $fee->taxable ? $fee->tax_class : 0,
				'amount'    => $fee->amount,
				'total'     => $fee->total,
				'total_tax' => $fee->tax,
				'taxes'     => array(
					'total' => $fee->tax_data,
				),
			)
		);

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

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