Automattic\WooCommerce\Internal\ShopperLists
ShopperList::add_item
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() 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;
}