我试图找到一种方法来使用WC_Order使用多个ID。使用单个ID时它工作正常,但多个不起作用。
$order_id = array("156","155","156"); // The order_id
// get an instance of the WC_Order object
$order = new WC_Order( $order_id )
// The loop to get the order items which are WC_Order_Item_Product objects since WC 3+
foreach( $order->get_items() as $item_id => $item_product ){
//Get the product ID
$item_product->get_product_id();
//Get the WC_Product object
$item_product->get_product();
}
答案 0 :(得分:1)
你需要循环每个id。
$order_ids = array("156","155","156"); // The order_id
foreach( $order_ids as $order_id ){
// get an instance of the WC_Order object
$order = new WC_Order( $order_id );
// The loop to get the order items which are WC_Order_Item_Product objects since WC 3+
foreach( $order->get_items() as $item_id => $item_product ){
//Get the product ID
$item_product->get_product_id();
//Get the WC_Product object
$item_product->get_product();
}
}