0

I want to get the "top earners" with highest revenues in my WooCommerce online shop. With

$top_10_products = new WP_Query(array("post_type" => "product", 
    "meta_key" => "total_sales", 
    "orderby" => "meta_value_num",
    "posts_per_page" => 10));

I get the most sold products. But what's the meta_key for "top earners"?

Thanks and best regards Martin

martinfre
  • 21
  • 2

1 Answers1

-1

Try below code

$args = array(
    'post_type' => 'product',
    'meta_key' => 'total_sales',
    'orderby' => 'meta_value_num',
    'posts_per_page' => 10,
);
$Query = new WP_Query( $args );
while ( $Query->have_posts() ) : $Query->the_post(); 
global $product; 

if (has_post_thumbnail( $Query->post->ID )) 
        echo get_the_post_thumbnail($Query->post->ID, 'shop_catalog'); 
        else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="product placeholder Image" width="65px" height="115px" />'; 

        the_title();

 endwhile; 
wp_reset_query(); 
Akshay Shah
  • 3,391
  • 2
  • 20
  • 33