Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
QueryBuilder::get_product_attributes_query
Return the tax_query for the requested attributes
Method of the class: QueryBuilder{}
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()
QueryBuilder::get_product_attributes_query() QueryBuilder::get product attributes query code WC 10.3.6
private function get_product_attributes_query( $attributes = array() ) {
if ( empty( $attributes ) ) {
return 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(
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
'tax_query' => array_values( $grouped_attributes ),
);
}