I have orders come in. Each order has a type i.e ‘Vanilla’ and a size i.e ‘Mini with a quantity.
If there are 5 Mini Vanillas I want it to display once not 5 times. I also want to tally the quantity.
Here is one of the many things I attempted
$prevSize = null;
$prevType= null;
foreach ($orders as $order){
echo '<tr>';
$new_order = new WC_Order();
$order_items = $new_order->get_items();
foreach ($order_items as $order_item ){
$currentSize = $order_item['pa_size'];
$currentType = wp_get_post_terms( $order_item['product_id'],'pa_ct');
$currentType = $currentType[0]->name;
if($prevSize != $currentSize){
echo $currentType . '<br>';
echo $currentSize . '<br>';
}
$count += $order_item['qty'];
echo $count;
}
$prevSize = $currentSize;
$prevType = $currentType;}
We have analyzed your query, and according to your need, here is my solution:
Above code will display each order type once not display multiple times. And display the quantity ordered in each order.