Featured products query WooCommerce

Author: Aleš Sýkora, 11. 4. 2021

If you are using your own queries for WooCommerce stores, for example in Oxygen builder's custom code block then you may need query for featured products.

You can use the query I am using inside my product sliders :-).

<div class="category-slider-big">

	<?php
		$args = array(
			'post_type' => 'product',
           	'post_status' => 'publish',
			'posts_per_page' => 12,
          'tax_query' => array( array(
            'taxonomy' => 'product_visibility',
            'field'    => 'term_id',
            'terms'    => 'featured',
            'operator' => 'IN',
        ) )
			);
		$loop = new WP_Query( $args );
		if ( $loop->have_posts() ) {
			while ( $loop->have_posts() ) : $loop->the_post();
          $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'medium_large'); 
          $permalink = get_permalink(get_the_ID());

?>
                      <div class="category-slider-big-cell c-padding-xs">
                <a href="<?php echo $permalink ?>">
                  <div class="c-transititon c-text-s baskerville text-up c-text-dark category-slider-text c-padding-xs"><?php the_title(); ?></div>
                  <img class="category-image" src="<?php echo $featured_img_url; ?>">
                </a>
            </div>

<?php
          
			endwhile;
		} else {
			echo __( 'No products found' );
		}
		wp_reset_postdata();
	?>
</div>