2 回答
TA贡献1789条经验 获得超8个赞
该问题与应为“商店订单”的订单类型有关。有两种方法:
1)检查订单类型,该类型必须为“ shop_order” (而不是“ shop_order_refund”)。因此,您可以使用方法get_type(),该方法也适用于WC_Order_Refund类似以下类的类:
foreach( $orders as $order ){
if ( $order->get_type() === 'shop_order' && $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>';
}
};
2)更改WC_Order_Query,仅定位“ shop_order”帖子类型:
$orders = wc_get_orders( array('limit' => -1, 'type' => 'shop_order') );
两种方式都将避免得到此致命错误
- 2 回答
- 0 关注
- 288 浏览
添加回答
举报