【问题标题】:WooCommerce custom report: Get orders with completed statusWooCommerce 自定义报告:获取已完成状态的订单
【发布时间】:2019-11-29 18:02:06
【问题描述】:

我正在为 woocommerce 制作自定义报告,我正在尝试为所有已交付订单添加报告,这就是我正在做的事情

        $orders = wc_get_orders( array('numberposts' => -1) );
    foreach( $orders as $order ){
    if ( $order->get_status() === completed){
        $order_data = $order->get_data(); // The Order data
        $items = $order->get_items();
        foreach ( $items as $item ) {
            $product_name = $item->get_name();
            $product_id = $item->get_product_id();
        }
        $orders_completed .=  '<tr><td>' . $order->get_order_number() . '</td>' .
        '<td>' . $order->get_date_created()->date('Y-m-d H:i:s') . '</td>' .
        '<td>' . $order->get_status() . '</td>' .
        '<td>' . $order->get_total() . '</td>' .
        '<td>' . $product_id . '</td>' .
        '<td>' . $product_name . '</td>' .
        '<td>' . $order->get_item_count() . '</td>' .
        '<td>' . $order->get_billing_first_name() . '</td>' .
        '<td>' . $order->get_billing_email() . '</td>' .
        '<td>' . $order->get_billing_phone() . '</td>' .
        '<td>' . $order_payment_method = $order_data['payment_method_title'] . '</td></tr>';
    }
}

我明白了

调用未定义的方法 WC_Admin_Order_Refund::get_order_number()

我不知道我做错了什么

【问题讨论】:

    标签: php wordpress methods woocommerce orders


    【解决方案1】:

    您只需在WC_Order_Query 中定位“shop_order” 帖子类型,没有“shop_order_refund” 帖子类型,因为某些WC_Order 方法不存在为WC_Order_Refund

    因此,您可以将代码的第一行替换为:

    $orders = wc_get_orders( array('limit' => -1, 'type' => 'shop_order') );
    

    这应该可以解决这个问题。

    the official documentation about wc_get_orders and WC_Order_Query

    【讨论】:

    • 我希望你在线 :D 问题解决了,非常感谢
    猜你喜欢
    • 2018-09-10
    • 1970-01-01
    • 2016-04-17
    • 2017-07-01
    • 2017-01-07
    • 1970-01-01
    • 2020-09-01
    • 2020-02-01
    • 2019-11-13
    相关资源
    最近更新 更多