• Resolved camouyer

    (@camouyer)


    Hello,

    I am looking to show the best selling products with the following shortcode : [products limit=”4″ columns=”4″ best_selling=”true” ] , However I would like only the INSTOCK product to show.

    How can I do that ?

    Any help is appreciated !

    Philippe

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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;
    }
    Thread Starter camouyer

    (@camouyer)

    Thank you so much ! it works perfectly !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show only INSTOCK product in the [products] shortcode’ is closed to new replies.