php - Hide all products with a specific stock status from WooCommerce catalog

one text

Solution:

You should better use dedicated woocommerce_product_query_meta_query filter hook as follows, to hide, from your store, all products that have a specific stock status (works with custom stock status):

add_action( 'woocommerce_product_query_meta_query', 'custom_product_query_meta_query', 1000 );
function custom_product_query_meta_query( $meta_query ) {
    if ( ! is_admin() ) {
        $meta_query[] = array(
            'key'     => '_stock_status',
            'value'   => 'noproduzione',
            'compare' => '!=',
        );
    }
    return $meta_query;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works on all versions since WooCommerce 3.

Source