WC_Brands::update_product_query_tax_query
Update the main product fetch query to filter by selected brands.
Method of the class: WC_Brands{}
No Hooks.
Returns
Array.
Usage
$WC_Brands = new WC_Brands(); $WC_Brands->update_product_query_tax_query( $tax_query );
- $tax_query(array) (required)
- array of current taxonomy filters.
WC_Brands::update_product_query_tax_query() WC Brands::update product query tax query code WC 10.3.3
public function update_product_query_tax_query( array $tax_query ) {
if ( isset( $_GET['filter_product_brand'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$filter_product_brand = wc_clean( wp_unslash( $_GET['filter_product_brand'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$brands_filter = array_filter( array_map( 'absint', explode( ',', $filter_product_brand ) ) );
if ( $brands_filter ) {
$tax_query[] = array(
'taxonomy' => 'product_brand',
'terms' => $brands_filter,
'operator' => 'IN',
);
}
}
return $tax_query;
}