0
votes

I tried to hide a category from my shop based on the factor that this category does not contain even 1 product that is in stock. If even 1 product is in stock then the category will appear.

I tried something like the code below with no avail:

function hide_out_of_stock_categories( $list_args ){
 if ( ! $product->managing_stock() && ! $product->is_in_stock() ){
            $list_args[ 'hide_empty' ] = 1;
            return $list_args;
}
}

I need to search first for the products inside the category and then check if the product stock status is in stock or out of stock, but I am missing something here.

1

1 Answers

0
votes

To hide or remove the empty categories listed here, add the following code lines at the end of your theme’s functions.php file.

function woo_hide_product_categories_widget( $list_args ){
 
      $list_args[ 'hide_empty' ] = 1;
 
      return $list_args;
 
}
 
add_filter( 'woocommerce_product_categories_widget_args', 'woo_hide_product_categories_widget' )