Bestsellers Woocommerce product loop

Wondering how you can make an loop with only the bestsellers of your products for you Woocommerce website?

It’s pretty simple! Just make a normal loop and make use of the pre-defined meta-key “total_sales” an order by the value.

The code

<?php
 $args = array(
  'post_type' => 'product',
  'posts_per_page' => 4,
  'meta_key' => 'total_sales',
  'orderby' => 'meta_value_num',
 );
 $loop = new WP_Query( $args );
 if ( $loop->have_posts() ) {
  while ( $loop->have_posts() ) : $loop->the_post();
   woocommerce_get_template_part( 'content', 'product' );
   endwhile;
 } else {
  echo __( 'No products found' );
 }
 wp_reset_postdata();
 ?>

Read more