WordPress at Your Fingertips
function is not described

WC_Abstract_Order::add_item() public WC 3.0.0

Adds an order item to this order. The order item will not persist until save.

{} It's a method of the class: WC_Abstract_Order{}

No Hooks.

Return

false|null.

Usage

$WC_Abstract_Order = new WC_Abstract_Order();
$WC_Abstract_Order->add_item( $item );
$item(WC_Order_Item) (required)
Order item object (product, shipping, fee, coupon, tax).

Changelog

Since 3.0.0 Introduced.

Code of WC_Abstract_Order::add_item() WC 5.8.0

public function add_item( $item ) {
	$items_key = $this->get_items_key( $item );

	if ( ! $items_key ) {
		return false;
	}

	// Make sure existing items are loaded so we can append this new one.
	if ( ! isset( $this->items[ $items_key ] ) ) {
		$this->items[ $items_key ] = $this->get_items( $item->get_type() );
	}

	// Set parent.
	$item->set_order_id( $this->get_id() );

	// Append new row with generated temporary ID.
	$item_id = $item->get_id();

	if ( $item_id ) {
		$this->items[ $items_key ][ $item_id ] = $item;
	} else {
		$this->items[ $items_key ][ 'new:' . $items_key . count( $this->items[ $items_key ] ) ] = $item;
	}
}