How to hide out of stock products using all products block
-
I am using a filter to hide out of stock products however when I inserted the All Products block on the home page the filter does not work for that block. I tried using the is_front_page condition but that does not work. Is there another condition I should use, or another filter altogether?
add_filter( 'woocommerce_product_query_meta_query', 'shop_only_instock_products', 10, 2 ); function shop_only_instock_products( $meta_query, $query ) { // Only on shop archive pages if( is_admin() || is_search() || ( !is_front_page() && !is_shop() && !is_product_category() && !is_product_tag() ) ) return $meta_query; $meta_query[] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => '!=' ); return $meta_query; }
Thank you!
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to hide out of stock products using all products block’ is closed to new replies.