Automattic\WooCommerce\Internal\ShopperLists

ShopperListItem::from_array │ public static │ WC 1.0

Construct from a stored item array (from user_meta).

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

Хуков нет.

Возвращает

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

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

$result = ShopperListItem::from_array( $data ): self;
$data(массив) (обязательный)
Stored item record.

Код ShopperListItem::from_array() WC 11.2.2

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'] ?? ''
	);
}