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.