Display featured products through custom loop in woocommerce on template page

Change your args to be like this:

$meta_query   = WC()->query->get_meta_query();
$meta_query[] = array(
    'key'   => '_featured',
    'value' => 'yes'
);
$args = array(
    'post_type'   =>  'product',
    'stock'       =>  1,
    'showposts'   =>  6,
    'orderby'     =>  'date',
    'order'       =>  'DESC',
    'meta_query'  =>  $meta_query
);

If you go to wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php (@595) you can find how it’s done for WC shortcodes.

Leave a Comment