我无法获得状态为 wc-pending/Pending Payment 的订单对象。它只是返回所有订单对象:
$my_course_query = new WP_Query( array(
'post_type' => 'shop_order',
'post_status' => 'wc-pending',
'posts_per_page' => -1
) );
最佳答案
Your code Is just working perfectly as expected, in frontend, I have test it and it output only orders with **pending status. So I can't tell what is your issue as your question is not detailed.
I have found this note on WordPress WP_Query reference that could be useful:
Note: Ticket #18408 For querying posts in the admin, consider using get_posts() as wp_reset_postdata() might not behave as expected.
一般来说,我不使用 WP_Query()
来处理客户订单,而是使用 wc_get_orders()
< em>(或者 get_posts()
也是) 这样:
$customer_orders = wc_get_orders( array(
'limit' => -1,
'status' => 'pending'
) );
// Iterating through each Order with pending status
foreach ( $customer_orders as $order ) {
// Going through each current customer order items
foreach($order->get_items() as $item_id => $item_values){
$product_id = $item_values['product_id']; // product ID
// Order Item meta data
$item_meta_data = wc_get_order_item_meta( $item_id );
// Some output
echo '<p>Line total for '.wc_get_order_item_meta( $item_id, '_line_total', true ).'</p><br>';
}
}
这也适用于获取订单对象。
关于php - 具有待定状态问题的 WP_Query 和 WooCommerce 订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952123/