WC_Order_Item_Data_Store::add_order_item()publicWC 3.0.0

Add an order item to an order.

Method of the class: WC_Order_Item_Data_Store{}

No Hooks.

Return

Int. Order Item ID

Usage

$WC_Order_Item_Data_Store = new WC_Order_Item_Data_Store();
$WC_Order_Item_Data_Store->add_order_item( $order_id, $item );
$order_id(int) (required)
Order ID.
$item(array) (required)
order_item_name and order_item_type.

Changelog

Since 3.0.0 Introduced.

WC_Order_Item_Data_Store::add_order_item() code WC 9.4.2

public function add_order_item( $order_id, $item ) {
	global $wpdb;
	$wpdb->insert(
		$wpdb->prefix . 'woocommerce_order_items',
		array(
			'order_item_name' => $item['order_item_name'],
			'order_item_type' => $item['order_item_type'],
			'order_id'        => $order_id,
		),
		array(
			'%s',
			'%s',
			'%d',
		)
	);

	$item_id = absint( $wpdb->insert_id );

	$this->clear_caches( $item_id, $order_id );

	return $item_id;
}