Automattic\WooCommerce\Internal\ShopperLists

ShopperList::add_itempublicWC 1.0

Add an item, or merge quantities if it already exists.

Method of the class: ShopperList{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ShopperList = new ShopperList();
$ShopperList->add_item( $item ): void;
$item(ShopperListItem) (required)
Item to add.

ShopperList::add_item() code WC 10.9.1

public function add_item( ShopperListItem $item ): void {
	$key = $item->get_key();

	if ( isset( $this->items[ $key ] ) ) {
		$this->items[ $key ] = ShopperListItem::from_array(
			array_merge(
				$this->items[ $key ]->to_array(),
				array( 'quantity' => $this->items[ $key ]->get_quantity() + $item->get_quantity() )
			)
		);
		return;
	}

	$this->items[ $key ] = $item;
}