wc_add_order_item( int $order_id, array $item_array )

Add a item to an order (for example a line item).


Description Description


Parameters Parameters

$order_id

(Required) Order ID.

$item_array

(Required) Items list.


Top ↑

Return Return

(int|bool) Item ID or false


Top ↑

Source Source

File: includes/wc-order-item-functions.php

function wc_add_order_item( $order_id, $item_array ) {
	$order_id = absint( $order_id );

	if ( ! $order_id ) {
		return false;
	}

	$defaults = array(
		'order_item_name' => '',
		'order_item_type' => 'line_item',
	);

	$item_array = wp_parse_args( $item_array, $defaults );
	$data_store = WC_Data_Store::load( 'order-item' );
	$item_id    = $data_store->add_order_item( $order_id, $item_array );
	$item       = WC_Order_Factory::get_order_item( $item_id );

	do_action( 'woocommerce_new_order_item', $item_id, $item, $order_id );

	return $item_id;
}


Top ↑

User Contributed Notes User Contributed Notes

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