I have and order\\u id as array但是wc_get_order
一次只接受一个id如何循环使用order\\u id并让项目id和项目名称的列表?我在课堂上使用这个。如果按如下所示传递单个id,则其工作正常
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;
}
请帮忙。谢谢
最合适的回答,由SO网友:ManzoorWani 整理而成
你可以这样做
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
}