问题
im making a custom reports for woocommerce im trying to add a report for all delivered orders here is what im doing
$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>';
}
}
i get
Call to undefined method WC_Admin_Order_Refund::get_order_number()
i don't know what im doing wrong
回答1:
You need to target only "shop_order" post type, without "shop_order_refund" post type in your WC_Order_Query
, because some WC_Order
methods doesn't exist for WC_Order_Refund
.
So you can replace instead the first line of your code by:
$orders = wc_get_orders( array('limit' => -1, 'type' => 'shop_order') );
This should solve this issue.
See the official documentation about wc_get_orders and WC_Order_Query
来源:https://stackoverflow.com/questions/57134533/woocommerce-custom-report-get-orders-with-completed-status