Show only INSTOCK product in the [products] shortcode

Hi Philippe( @camouyer ),

Add the below code snippet in the active theme functions.php file to display only the INSTOCK products.

add_filter('woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_instock_best_selling', 10, 3);

function woocommerce_shortcode_products_instock_best_selling($query_args, $attributes, $type) {

if ('best_selling_products' === $type) {

$query_args['meta_query'][] = array(
'key' => '_stock_status',
'value' => 'instock',
);
}
return $query_args;
}

Thank you so much ! it works perfectly !

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer