Automattic\WooCommerce\Internal\ProductFeed\Mapping

UcpProductMapper::variation_options_by_id │ private │ WC 1.0

Build each visible variation's selected options from the parent item.

An attribute left as "Any" on a variation has a null value and is omitted.

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

Хуков нет.

Возвращает

array. Variation id => list of { name, label }.

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

// private - только в коде основоного (родительского) класса
$result = $this->variation_options_by_id( $item ): array;
$item(массив) (обязательный)
Store API item response of the variable product.

Код UcpProductMapper::variation_options_by_id() WC 11.3.0

private function variation_options_by_id( array $item ): array {
	$names   = $this->term_names( $item );
	$options = array();

	foreach ( (array) $item['variations'] as $variation ) {
		$selected = array();

		foreach ( (array) $variation['attributes'] as $attribute ) {
			if ( null === $attribute['value'] || '' === (string) $attribute['value'] ) {
				continue;
			}

			$name       = (string) $attribute['name'];
			$value      = (string) $attribute['value'];
			$selected[] = array(
				'name'  => $name,
				'label' => $names[ $name ][ $value ] ?? $value,
			);
		}

		$options[ (int) $variation['id'] ] = $selected;
	}

	return $options;
}