I'm trying to write the product name and quantity from a given order, then read from the next order and add to the array but the final array only stores the value from the last loope I don't know what I'm doing wrong, I also tried array_push I would like to count the number of units sold and display as follows for all orders: Product A - 50 pieces Product B - 30 pieces, etc.
foreach ($order_id as $order_ids) {
//echo '</br>' . $vendor_id . ' ' . $vendor_mail . ' ' . $vendor_name . '</br>';
$orderID = $order_ids->order_id;
$order_date = $order_ids->date_created;
$single_order = wc_get_order($orderID);
echo '</br>';
echo __('ID zamówienia: ') . $orderID . '<br>';
echo __('Data zamówienia: ') . $order_date . '<br>';
$product_quantity = array();
$product_name = array();
$single_order_array=array();
$array_merge=array();
foreach ($single_order->get_items() as $item) {
echo __('Nazwa produktu: ') . $item->get_name() . '<br>';
echo __('Ilość: ') . $item->get_quantity() . '<br><br><br>';
$product_quantity[] = $item->get_quantity();
$product_name[] = $item->get_name();
$single_order_array=array_combine($product_name, $product_quantity);
}
echo '</br>TABLICA POJEDYNCZEGO ZAMOWIENIA: </br>';
print_r($single_order_array);
echo '</br></br>';
$array_merge=array_replace_recursive($single_order_array, $array_merge);
}
echo '</br>TABLICA CAŁEGO WENDORA : </br>';
print_r($array_merge);
echo '</br></br>';
}