Since the introduction of Bookings version 1.10.0 meta data associated with a booking has been removed from WooCommerce orders. This may add a level of frustration, particularly when using some sort of exporter which would have effortlessly fetched the booking data if that data were part of the order line item data. This is an unfortunate side effect of streamlining for performance. The removal of the meta data from the order does help with performance in reducing database size which, in turn, speeds up queries.
The good news is that the booking data can still be retrieved via some custom code. It’s a bit cumbersome, but possible. Bookings does provide a method named get_booking_ids_from_order_id which can be used to get all of the booking ids from an order number. The booking id is needed in order to query the booking for whatever data you are trying to retrieve. Here’s a code sample (this sample assumes that you have access to the WooCommerce order object):
That will simply populate the $booking_ids variable with the return value of get_booking_ids_from_order_id
Once you have the booking id(s), you could then retrieve whatever data from those bookings that are needed. Bookings does provide some CRUD methods for this, i.e. the person count for a booking can be retrieved via the get_person_counts method. Using the $booking_ids array from above, you can get the persons count via something like this:
Putting it all Together
In the case of exporting, you may want to get a person count for each of the bookings in an order. If we use the official developer documentation for the WooCommerce Order Customer CSV export as a baseline and make some tweaks to it, we can add a column to our export and populate that column with the person counts for each booking using something like this:
There is obviously more that can be done with that, but hopefully this gives you a pointer in the right direction.
Not sure what to do with code snippets? See What Do I Do With These Code Snippets?