Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_product_attributes_query()privateWC 1.0

Return the tax_query for the requested attributes

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_product_attributes_query( $attributes );
$attributes(массив)
Attributes and their terms.
По умолчанию: array()

Код ProductQuery::get_product_attributes_query() WC 8.7.0

private function get_product_attributes_query( $attributes = array() ) {
	$grouped_attributes = array_reduce(
		$attributes,
		function ( $carry, $item ) {
			$taxonomy = sanitize_title( $item['taxonomy'] );

			if ( ! key_exists( $taxonomy, $carry ) ) {
				$carry[ $taxonomy ] = array(
					'field'    => 'term_id',
					'operator' => 'IN',
					'taxonomy' => $taxonomy,
					'terms'    => array( $item['termId'] ),
				);
			} else {
				$carry[ $taxonomy ]['terms'][] = $item['termId'];
			}

			return $carry;
		},
		array()
	);

	return array(
		'tax_query' => array_values( $grouped_attributes ),
	);
}