WC_Checkout::create_order_line_items()publicWC 1.0

Add line items to the order.

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

Возвращает

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

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

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

Код WC_Checkout::create_order_line_items() WC 8.7.0

public function create_order_line_items( &$order, $cart ) {
	foreach ( $cart->get_cart() as $cart_item_key => $values ) {
		/**
		 * Filter hook to get initial item object.
		 *
		 * @since 3.1.0
		 */
		$item                       = apply_filters( 'woocommerce_checkout_create_order_line_item_object', new WC_Order_Item_Product(), $cart_item_key, $values, $order );
		$product                    = $values['data'];
		$item->legacy_values        = $values; // @deprecated 4.4.0 For legacy actions.
		$item->legacy_cart_item_key = $cart_item_key; // @deprecated 4.4.0 For legacy actions.
		$item->set_props(
			array(
				'quantity'     => $values['quantity'],
				'variation'    => $values['variation'],
				'subtotal'     => $values['line_subtotal'],
				'total'        => $values['line_total'],
				'subtotal_tax' => $values['line_subtotal_tax'],
				'total_tax'    => $values['line_tax'],
				'taxes'        => $values['line_tax_data'],
			)
		);

		if ( $product ) {
			$item->set_props(
				array(
					'name'         => $product->get_name(),
					'tax_class'    => $product->get_tax_class(),
					'product_id'   => $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id(),
					'variation_id' => $product->is_type( 'variation' ) ? $product->get_id() : 0,
				)
			);
		}

		$item->set_backorder_meta();

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

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