如何解决Woocommerce Group上按供应商签收时间在一个循环中每个订单商品的总计数
我正在尝试获取所有处于保留状态的订单以及每个订单的总数,并将其显示在页面上。
按此顺序,我通过使用ACF插件创建元框保存变量,将其分配给角色(shop_manager)。这些变量对该角色的用户的顺序为(shop_manager)。
现在,在12:00 PM,我选择5个订单并将其分配给用户角色(shop_manager),并在3:00 pm选择不同的3个订单并将其分配给用户角色(shop_manager)。
现在,用户角色(shop_manager)转到自定义页面Callet供应商,查看所有订单项,并查看其数量。
我需要什么,我尝试向用户显示此拖曳订单,我可以为他显示订单的所有项目,但事实并非如此,它必须看到拖曳订单并单击任意一个并查看所有订单
并希望获得每种产品的总称
那怎么办?
global $woocommerce;
//custom array to list products:
$products_array = array();
$userID = get_current_user_id();
//start wp query
$args = array(
'post_type' => 'shop_order','post_status' => 'wc-on-hold','meta_key' => 'user_to_asign','meta_value' => $userID,'posts_per_page'=> -1
);
$loop = new WP_Query( $args );
//loop through orders
while ( $loop->have_posts() ) {
$loop->the_post();
//vars
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
$product_details = array();
$order_items = $order->get_items();
//loop through products
foreach( $order_items as $product ) {
//if product has been captured to custom array before,increment value,else add it.
if (array_key_exists($product['name'],$products_array)) {
$products_array[$product['name']] += $product['qty'];
} else {
$products_array[$product['name']] = $product['qty'];
}
}
}
//end wp_query
wp_reset_postdata();
echo '<table class="table table-striped table-dark">
<thead>
<tr>
<th scope="col">اسم المنتج</th>
<th scope="col">الكمية</th>
<th scope="col">التوافر</th>
</tr>
</thead>
<tbody>';
//display list:
foreach ($products_array as $title => $quantity) {
echo '
<tr>
<th scope="row">'.$title.'</th>
<td>'.$quantity.'</td>
<td> - </td>
</tr>';
}
echo '
</tbody>
</table>';
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。