Display WooCommerce Featured Products

Complexity Low
Compatibility WordPress 5.4, 5.5+WooCommerce 4+

Overview

Setting featured products is critical for your WooCommerce store by allowing you to display products that are either your top sellers, the focus of your business, or may be a new offering. Either way, WooCommerce provides this functionality out of the box. This recipe will go through how to set a product as a "featured product" and display those products anywhere in your theme.

To set a product as a featured product, click the Star icon (shown below) on the product listing page.

How to set a featured product in WooCommerce

You can grab featured products using a simple WP Query to grab only the featured products. This can be placed in any theme template where you want to display these products:

$args = array(
    'posts_per_page' => -1, // Grabs all of the featured products. Limit if needed
    'post_type'      => 'product', // Ensures the post type is a product
    'post_status'    => 'publish', // Ensures the product is published
    'tax_query'      => array(
        array(
            'taxonomy' => 'product_visibility', // Does a meta query on product visibility
            'field'    => 'name',
            'terms'    => 'featured', // Makes sure we grab all products flagged as featured
            'operator' => 'IN',
            ),
        )  
);
$featuredProducts = new WP_Query( $args );

Place this in your template file where you want to display your featured products. Within the loop you have access to a post object now that you can call all of your post methods on.

while( $featuredProducts->have_posts() ){
    $featuredProducts->the_post(); 
}

Usage Ideas

  • Displaying a featured product grid

Similar Recipes