php - 具有待定状态问题的 WP_Query 和 WooCommerce 订单

标签 php wordpress woocommerce foreach orders

我无法获得状态为 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>';
    }
}

这也适用于获取订单对象。

相关文档:wc_get_orders and WC_Order_Query

关于php - 具有待定状态问题的 WP_Query 和 WooCommerce 订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952123/

相关文章:

php - fatal error : Class 'MongoDB\Driver\Manager' not found

css - Bootstrap : horizontal centering and background color for image link on phone

wordpress - WooCommerce:使用 PayPal 和 notify_URL

php - 替换 WooCommerce PayPal 结帐网关插件结帐页面上的图标

PHP If/Else 语句在 While 循环中不起作用

php - html特殊字符源代码

php - 基于 CSS :root variables 动态生成 add_theme_support( 'editor-color-palette') 颜色

php - 使用 mqtranslate plus 在 wordpress 上翻译菜单上的自定义链接

php - 基于用户角色的 Woocommerce 最小订单总额

javascript - 我的表单设计逻辑有哪些缺点?