Hide ‘out of stock’ products in Woocommerce

Hide ‘out of stock’ products in Woocommerce

OR

How to hide out of stock products using meta query in wordpress

add_filter(‘woocommerce_product_query_meta_query’ , ‘hide_outofstock_from_best_sellers’);

function hide_outofstock_from_best_sellers($meta_query,$q){

global $wp_query;

$meta_query[‘stock_status’]  =

array(    array(

‘key’       => ‘_stock_status’,

‘value’     => ‘outofstock’,

‘compare’   => ‘NOT IN’

));

return $meta_query;

}