Based on Get all persons as a sum from all WooCommerce bookings answer code to my previous related question, I am using the following code to get all persons as a sum from all the related WooCommerce bookings:
// get all bookings Ids with a status "complete"
$bookings_ids = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'wc_booking', // booking post type
'post_status' => 'complete',
'fields' => 'ids',
));
$persons_count = 0; // Initializing
$persons_html = '<table><tr><th>Booking id</th><th>Persons count</th></tr>'; // Initializing
// Loop through booking Ids
foreach ( $bookings_ids as $booking_id ) {
$booking = new WC_Booking( $booking_id ); // Get the WC_Booking instance object
$count = array_sum( $booking->get_person_counts() );
$persons_count += $count;
$persons_html .= '<tr><td>' . $booking_id . '</td><td>' . $count . '</td></tr>';
}
$persons_html .= '<tr><th><strong>Total count</th><td style="color:red">' . $persons_count . '</td></tr>';
// Output
echo $persons_html . '</table>';
That works fine, but now I am trying to summarize the output by date.
So for example we have several bookings for 2021-02-10 with 85 people at all and
several bookings for 2021-02-11 with 45 people at all.
So I get the total amount of 130 people at all. Bu how I can change the code to summarized the total amount by date?
question from:
https://stackoverflow.com/questions/66048427/get-all-persons-as-a-sum-from-all-woocommerce-bookings-summarized-by-date 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…