Sarathlal N

Display featured products - WooCommerce

In WooCommerce, there is an option to make a product as featured one. That means, we can simply highlight / list out our special products.

To display featured products, we have two options.

Using Short Code

[featured_products per_page="8" columns="4" orderby="date" order="desc"]

Using WordPress Query

$args = array(  
	'post_type' => 'product',
	'post_status' => 'publish', 
	'tax_query' => array(
		array(
			'taxonomy' => 'product_visibility',
			'field'    => 'name',
			'terms'    => 'featured',
			'operator' => 'IN'
		),
	),
	'posts_per_page' => 4,
	'orderby' => 'menu_order',
    'order' => 'ASC'  
);  
  
$featured_query = new WP_Query( $args );  
	  
if ($featured_query->have_posts()) :   
  
	while ($featured_query->have_posts()) :   
	  
		$featured_query->the_post();  
		  
		$product = get_product( $featured_query->post->ID );  
		  
		// Output product information here
		var_dump($product);
		  
	endwhile;  
	  
endif;  
  
wp_reset_query(); // Reset Our Query

Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!

Recent Posts

  1. Scaling WordPress - How Custom Database Tables Solve the Post Meta Bottleneck
  2. WordPress Transients Explained - A Developer's Guide to Site Performance
  3. Behind the Click - The Hidden Journey of Your Web Requests
  4. Automating Code Linting with GitHub Actions for WordPress Plugins
  5. Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.