I use the official woocommerce booking plugin and I try do get the quantity of all persons that have booked a product.
for a single order that’s no problem with:
if ( is_callable( 'WC_booking_Data_Store::get_booking_ids_from_order_id') ) {
$booking_data = new WC_booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order->get_id() );
}
foreach ( $booking_ids as $booking_id ) {
$booking = new WC_booking( $booking_id );
$person_count = array_sum( $booking->get_person_counts() );
$total_person_count .= 'Booking id: ' . $booking_id . ' Person Count: ' . $person_count . ' ';
}
but how can I collect the sum of all bookings? Hope you can help me
2
Answers
following your updated code, please try this
To get all "complete" bookings persons count use the following:
Tested and works.
To make it lighter, you could replace:
simply by: