WooCommerce Get Top Seller Product

Today we are going to talk about how to get top seller products in WooCommerce or wordpress. This tutorial will be helpful to place your top seller products in one place.

Below is an example:

$queryargs = array(
               'post_type' => 'product',
                'meta_key' => 'total_sales',
                'orderby' => 'meta_value_num',
            'order' => 'DESC',
                'post_status' => 'publish',
                'posts_per_page' => 10,
      );
$query = new WP_Query( $queryargs );
while ( $query->have_posts() ) {           
        $query->the_post();            
        $totalSales =   get_metadata( 'post', $query->post->ID, 'total_sales', true );
        if($totalSales){         
          if($totalSales[0] > 0) {       
              echo the_title();
          }        
      }      
}

Here is an available free WooCommerce top seller product extension.

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!