admin管理员组文章数量:1130349
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
Share Improve this question asked Oct 17, 2018 at 12:31 user145078user1450781 Answer
Reset to default 0You 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
}
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
Share Improve this question asked Oct 17, 2018 at 12:31 user145078user1450781 Answer
Reset to default 0You 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
}
本文标签: functionshow to handle multiple forloop
版权声明:本文标题:functions - how to handle multiple forloop? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749254950a2340323.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论