在 WC_Order 中使用多个 ID - Woocommerce
Using multiple ids with WC_Order - Woocommerce
我正在尝试找到一种方法来通过 WC_Order 使用多个 ID。它在使用单个 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();
}
你需要在每个 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();
}
}
我正在尝试找到一种方法来通过 WC_Order 使用多个 ID。它在使用单个 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();
}
你需要在每个 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();
}
}