I am using simple and variations products with active manage stock.

I need to list only products with stock quantity > 0 in frontend search and categories.

I am trying the follow code, but does not work.

```
add_action( 'pre_get_posts', 'show_only_products_with_qtdy_min_1' );

function show_only_products_with_qtdy_min_1( $query ) {

    // $query->is_search

    if( ! is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product' ) {
        //Get original meta query
        $meta_query = $query->get('meta_query');

        // Add your criteria
        $meta_query[] = array(
                'key'     => '_stock_quantity',
                'value'   => 0,
                'compare' => '>'
        );    
        // print_r($meta_query); exit();
        // Set the meta query to the complete, altered query
        $query->set('meta_query',$meta_query);
    }
};

```