Automattic\WooCommerce\Internal\ShopperLists

ShopperList::add_itempublicWC 1.0

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

Метод класса: ShopperList{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$ShopperList = new ShopperList();
$ShopperList->add_item( $item ): void;
$item(ShopperListItem) (обязательный)
Item to add.

Код ShopperList::add_item() 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;
}