WC_Order_Item_Data_Store::add_order_item( int $order_id, array $item )

Add an order item to an order.


Description Description


Parameters Parameters

$order_id

(Required) Order ID.

$item

(Required) order_item_name and order_item_type.


Top ↑

Return Return

(int) Order Item ID


Top ↑

Source Source

File: includes/data-stores/class-wc-order-item-data-store.php

	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;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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