Automattic\WooCommerce\Internal\ShopperLists

ShopperListItem::from_arraypublic staticWC 1.0

Construct from a stored item array (from user_meta).

Method of the class: ShopperListItem{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ShopperListItem::from_array( $data ): self;
$data(array) (required)
Stored item record.

ShopperListItem::from_array() code WC 10.9.1

public static function from_array( array $data ): self {
	if (
		empty( $data['key'] ) || ! is_string( $data['key'] )
		|| empty( $data['product_id'] ) || ! is_int( $data['product_id'] )
		|| empty( $data['quantity'] ) || ! is_int( $data['quantity'] )
	) {
		throw new \Exception( 'Shopper list item requires "key" (string), "product_id" (int), and "quantity" (int).' );
	}

	return new self(
		$data['key'],
		absint( $data['product_id'] ),
		absint( $data['variation_id'] ?? 0 ),
		$data['variation'] ?? array(),
		absint( $data['quantity'] ),
		$data['date_added_gmt'] ?? current_time( 'mysql', true ),
		$data['product_title_at_save'] ?? ''
	);
}