Automattic\WooCommerce\Blocks\BlockTypes
ProductQuery::get_product_attributes_query
Return the tax_query for the requested attributes
Method of the class: ProductQuery{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_product_attributes_query( $attributes );
- $attributes(array)
- Attributes and their terms.
Default: array()
ProductQuery::get_product_attributes_query() ProductQuery::get product attributes query code WC 10.3.6
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 ),
);
}