Woocommerce WP - 从post_type = shop_order |获取_sku值SQL QUERY

时间:2017-08-07 19:32:14

标签: php mysql wordpress woocommerce shop

Woocommerce wp_posts 中有两种类型的post_type,' 产品 '& '的 shop_order '。

shop_order ID ,我在哪里可以获得 _sku wp_postmeta 包含 _sku ,它直接连接到post_type = 'product'而不是{{1} }}。到目前为止,有一个:

post_type = 'shop_order'

如何在此SQL查询中打印 _sku值? 从 shop_order 产品 SELECT oi.order_item_id, oi.order_item_name, oi.order_item_type, oi.order_id, max( CASE WHEN oim.meta_key = '_line_subtotal' and oim.order_item_id = oi.order_item_id THEN oim.meta_value END ) as _line_subtotal, max( CASE WHEN oim.meta_key = '_line_total' and oim.order_item_id = oi.order_item_id THEN oim.meta_value END ) as _line_total, max( CASE WHEN oim.meta_key = '_product_id' and oim.order_item_id = oi.order_item_id THEN oim.meta_value END ) as _product_id, max( CASE WHEN oim.meta_key = '_variation_id' and oim.order_item_id = oi.order_item_id THEN oim.meta_value END ) as _variation_id, max( CASE WHEN oim.meta_key = '_qty' and oim.order_item_id = oi.order_item_id THEN oim.meta_value END ) as _quantaty FROM wp_woocommerce_order_items oi INNER JOIN wp_woocommerce_order_itemmeta oim on oi.order_item_id = oim.order_item_id where oi.order_id=:order_item group by oi.order_item_id "); $sth2->bindParam(':order_item', $_GET["order"], PDO::PARAM_STR); $sth2->execute(); 的原始页面ID的连接在哪里

_sku值位于wp_postmeta中:

post_type = 'product'

1 个答案:

答案 0 :(得分:0)

以下是查找特定产品的woocommerce订单的查询:

select ord.ID
from wp_posts prd
join wp_woocommerce_order_itemmeta om on om.meta_key = '_product_id' and om.meta_value = prd.ID
join wp_woocommerce_order_items o on o.order_item_id = om.order_item_id
join wp_posts ord on ord.ID = o.order_id
where prd.ID = [Specific product ID]