Remove products from category when status is "in-stock"

Viewed 37

I need a little help. I need to hide category which will contain few out-of-stock products and I get it done with this code

function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'u-dolasku' ), // Don't display products in the clothing category on the shop page.
           'operator' => 'NOT IN'
    );


    $q->set( 'tax_query', $tax_query );

    }

add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Now I have a question, is it possible to remove product from that category when stock is updated, exactly when stock status go from "out-of-stock" to "in-stock" ?

0 Answers
Related