Displaying Featured Products in WooCommerce

WooCommerce has products called Featured Products which are products what become featured when they are starred in the WP Admin dashboard.

woocommerce-featured-products

Here is how you can display them.

 

Featured Products Shortcode

Display WooCommerce Featured Products via shortcode like so:

[featured_products per_page="9" columns="3"]

Other parameters you can use in the shortcode are ‘orderby‘ and ‘order‘.

Featured Products Custom Loop

Display WooCommerce Featured Products via a custom loop like so:

Above I am creating a loop with an infinite amount of featured products by setting the value ‘-1’ to the ‘post_per_page’ key, in the loop markup output  I am using some regular WooCommerce css classes to the display of the data and my own data structure of the parts of the product I want to display.

Featured Products Shortcode Custom Loop

Display WooCommerce Featured Products via a shortcode custom loop like so:

Above is pretty much the same as the previous loop – this time shortcode is created which needs to be added to an area to display it, only 3 products will show. Shortcode is:

[woo_featured]

Also commented out is …

//  wc_get_template_part( 'content', 'product' );

You could use this instead of the custom output to render the default WooCommerce output.

6 comments

  • This is awesome!

    Could you show us how you would add the price to the loop?
    I have tried and it’s been giving me a critical error.

    Thanks!

  • Alan Greaves

    Where is this code added as it can’t be placed directly on the page like a shortcode can? Is it placed in a function that is then added as a shortcode or is another method of deploying it used?

    • A

      The first code block would need to be wrapped in a function and have an action hook added and put in functions.php – the second block is a shortcode add it to functions.php and use the shortcode in your themes front end if you want to add the shortcode instead to a backend php template you would use

      <?php echo do_shortcode("[woo_featured]"); ?>
  • This was extremely helpful in creating a custom loop for my client’s homepage.

    I added in the price by calling:
    $price = get_post_meta( get_the_ID(), ‘_regular_price’, true);
    $sale = get_post_meta( get_the_ID(), ‘_sale_price’, true);

    within the `while loop`, then output it using:

    $

    $

    Thanks for starting me off with some easy to follow snippets :)

  • hello there,
    thank you for your work, the code work prefect however, i am trying to get only 2 columns next to each other. i tried changing columns-3 to columns-2 but the products not next to each other.
    so could you please help me with this.

    Thanks in advance.

  • I didn’t find this helpful. I need to know how to make a link to all featured products – that is all. I get that the link should have a “?” followed by a parameter that specifies featured. This is all I want. Not this. Can you help?

Leave your comment