2017-10-09 72 views
0

我想在我的WooCommerce在線商店中獲得收入最高的「最高收入者」。 With如何獲得WooCommerce的「最高收入者」

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

我得到的是銷量最高的產品。但是對於「頂級收入者」來說,meta_key是什麼?

感謝和問候馬丁

回答

0

試試下面的代碼

$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(); 
+0

謝謝,但這是「最暢銷的產品。」我需要「最高收入者」。 – martinfre

相關問題