Automattic\WooCommerce\Internal\ShopperLists

ShopperList::from_arrayprivate staticWC 1.0

Build a ShopperList from a stored array.

Method of the class: ShopperList{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ShopperList::from_array( $data, $user_id ): self;
$data(array) (required)
Stored list record.
$user_id(int) (required)
Owning user ID.

ShopperList::from_array() code WC 10.9.1

private static function from_array( array $data, int $user_id ): self {
	$items = array();
	if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
		foreach ( $data['items'] as $key => $item_data ) {
			if ( ! is_array( $item_data ) ) {
				continue;
			}

			try {
				$items[ (string) $key ] = ShopperListItem::from_array( $item_data );
			} catch ( \Throwable $e ) {
				continue;
			}
		}
	}

	return new self(
		$user_id,
		$data['slug'] ?? '',
		$data['date_created_gmt'] ?? current_time( 'mysql', true ),
		$items
	);
}