I am using WooCommerce Bookings plugin and I currently looking to display additional information in the booking summary (product options).
To do this I use the following hook: woocommerce_admin_booking_data_after_booking_details
If my reservation is linked to an order, I retrieve my data using the function wc_get_order_item_meta
I would like to be able to retrieve my data when the reservation is not yet an order (simply added to the basket for example).
When browsing the database I saw that the information was stored in the table woocommerce_sessions
.
In the hook I use, I only have access to the ID of the reservation.
Is it possible to retrieve the corresponding session from this one?
Thanks
UPDATE
add_filter('woocommerce_admin_booking_data_after_booking_details', function ($booking_id) {
global $wpdb;
$booking = get_wc_booking($booking_id);
$order = $booking->get_order();
if ($order) {
foreach ($order->get_items() as $item) {
$item_meta = wc_get_order_item_meta($item->get_id(), '', FALSE);
/* Your code */
}
} else {
$table = $wpdb->prefix . 'woocommerce_sessions';
$condition = '%booking_id____' . $booking_id . '%';
$sql = "SELECT session_value FROM $table WHERE session_value LIKE '$condition'";
$query = maybe_unserialize($wpdb->get_var($sql));
$cart_items = maybe_unserialize($query['cart']);
foreach ($cart_items as $item) {
/* Your code */
}
}
}, 10, 1);