如何通过产品ID wordpress获得woocommerce订单?

时间:2017-02-16 13:23:28

标签: wordpress woocommerce

我想通过产品ID过滤woocommerce中的所有订单 防爆。如果我想知道产品ID为123的产品XYZ的订单数量。

由于

1 个答案:

答案 0 :(得分:6)

您可以使用以下查询获取结果:

$results = $wpdb->get_results( 
   'SELECT wpp.order_item_id as OrderPrimaryID,wpp.order_id as OrderID,
           wpm.meta_value as OrderProductId,wpsot.post_author as OrderPostAuthor,
           wpu.ID as OrderUserID,wpu.user_email as OrderUserEmail FROM wp_woocommerce_order_items as wpp 
    INNER JOIN wp_woocommerce_order_itemmeta as wpm ON wpp.order_item_id=wpm.order_item_id 
    INNER JOIN wp_posts wpsot ON wpp.order_id=wpsot.ID 
    INNER JOIN wp_postmeta wppostmeta ON wpp.order_id=wppostmeta.post_id 
    INNER JOIN wp_users wpu ON wppostmeta.meta_value=wpu.ID 
    WHERE wpm.meta_key="_product_id" AND wppostmeta.meta_key="_customer_user"', 
    OBJECT 
);
print_r($results);

希望它有所帮助。