I have and order_id as array but wc_get_order
accepts only one id at a time how to loop through order_id and let the list of item id and item name? i am using this inside a class. it works fine if single id is passed as shown below
public function getStuffDone()
{
order_id =array(358,368)
$order = wc_get_order(358);//only single id is passed here
$items = $order->get_items();
foreach ($order->get_items() as $item_key => $item_values):
$item_id = $item_values->get_id();
$item_name = $item_values->get_name();
endforeach;
return $item_name;
}
please help .thanks
I have and order_id as array but wc_get_order
accepts only one id at a time how to loop through order_id and let the list of item id and item name? i am using this inside a class. it works fine if single id is passed as shown below
public function getStuffDone()
{
order_id =array(358,368)
$order = wc_get_order(358);//only single id is passed here
$items = $order->get_items();
foreach ($order->get_items() as $item_key => $item_values):
$item_id = $item_values->get_id();
$item_name = $item_values->get_name();
endforeach;
return $item_name;
}
please help .thanks
You can do something like this
public function getStuffDone() {
$order_ids = array( 358,368 );
$items = array(); // contains the names
foreach ( $order_ids as $order_id ) {
$order = wc_get_order( $order_id );
foreach ( $order->get_items() as $item_values ) {
$items[ $order_id ][] = $item_values->get_name(); // add the name to the array
}
}
return $items; // array containing all the names
}