I know that the orders reside in the wp_posts table, with the post_type of shop_order. And the wp_postmeta table holds the information about each order such as name, address, status, etc. However, what I'm missing is the item that the user ordered.
我知道订单位于wp_posts表中,其中包含shop_order的post_type。wp_postmeta表包含关于每个订单的信息,如名称、地址、状态等。但是,我缺少的是用户所订购的项目。
I can't find what the relationship is in the database to pull that info.
我找不出数据库中有什么关系来提取信息。
Could someone point me in the right direction?
有人能给我指出正确的方向吗?
3 个解决方案
#1
1
Why not let WooCommerce get the items for you?
为什么不让WooCommerce帮你拿到这些东西呢?
// create the order object
$order = wc_get_order( $order_id );
// retrieve the items associated with that order
$order_items = $order->get_items();
// dump the array of returned items
var_dump($order_items);
#2
1
If i understood your question this is what you need:
如果我理解你的问题,这就是你需要的:
$sql = "SELECT * FROM wp_posts "
. " INNER JOIN wp_postmeta ON wp_posts.id = wp_postmeta.post_id"
. " WHERE wp_posts.ID = " . $postId;
Then see the wp_postmeta
keys.
然后查看wp_postmeta键。
#3
0
Orders are stored as posts as you said.
订单按您说的方式存储。
For products, you have to go on wp_woocommerce_order_items and wp_woocommerce_order_itemmeta
对于产品,您必须使用wp_woocommerce_order_items和wp_woocommerce_order_itemmeta。
There is an example of join
有一个连接的例子
inner join wp_woocommerce_order_items as woi on ( woi.order_id = posts.ID )
inner join wp_woocommerce_order_itemmeta as woim on ( woim.order_item_id = woi.order_item_id )
#1
1
Why not let WooCommerce get the items for you?
为什么不让WooCommerce帮你拿到这些东西呢?
// create the order object
$order = wc_get_order( $order_id );
// retrieve the items associated with that order
$order_items = $order->get_items();
// dump the array of returned items
var_dump($order_items);
#2
1
If i understood your question this is what you need:
如果我理解你的问题,这就是你需要的:
$sql = "SELECT * FROM wp_posts "
. " INNER JOIN wp_postmeta ON wp_posts.id = wp_postmeta.post_id"
. " WHERE wp_posts.ID = " . $postId;
Then see the wp_postmeta
keys.
然后查看wp_postmeta键。
#3
0
Orders are stored as posts as you said.
订单按您说的方式存储。
For products, you have to go on wp_woocommerce_order_items and wp_woocommerce_order_itemmeta
对于产品,您必须使用wp_woocommerce_order_items和wp_woocommerce_order_itemmeta。
There is an example of join
有一个连接的例子
inner join wp_woocommerce_order_items as woi on ( woi.order_id = posts.ID )
inner join wp_woocommerce_order_itemmeta as woim on ( woim.order_item_id = woi.order_item_id )