Check if any available product has specific attribute
Here is the code that solved the problem: $woo_args = array( ‘status’ => ‘publish’, ‘limit’ => 1, ‘stock_status’ => ‘instock’, ‘brand’ => 99 ); $products = wc_get_products($woo_args); if (count($products) == 0){ //No product with the custom attribute id=99 } add_filter(‘woocommerce_product_data_store_cpt_get_products_query’, ‘my_handle_custom_query_var’, 10, 2); function my_handle_custom_query_var($query, $query_vars) { if (!empty($query_vars[‘brand’])){ $query[‘tax_query’][] = array( ‘taxonomy’ => ‘pa_brand’, … Read more