I swiftly went through five other posts on Stack Overflow in an attempt to modify the code for the correct answer. Some of them looked promising, but none of them yielded the desired results. Consequently, I decided to begin from scratch.
My objective is to:
- Add column on the WooCommerce Orders page.
- Visit mywebsite.com/wp-admin/edit.php?post_type=shop_order and see column with dates
- Include booking start and booking end dates in that column.
- there is always just one booking per order
Here's the code I've developed thus far that adds the column to the order page:
// Add custom column to WooCommerce admin orders page
function custom_add_booking_dates_column($columns) {
// Add the custom column after the "Order Actions" column
$columns['booking_dates'] = __('Booking Dates', 'text-domain');
return $columns;
}
add_filter('manage_edit-shop_order_columns', 'custom_add_booking_dates_column');
// Populate the custom column with "Testing" text
function custom_populate_booking_dates_column($column) {
global $post;
if ($column === 'booking_dates') {
// Output the text you want to display in the custom column
echo 'Testing';
}
}
add_action('manage_shop_order_posts_custom_column', 'custom_populate_booking_dates_column');
Things I've tried:
- Editing wp-config and increasing memory
- Turning on debug to solve (was getting
wc_booking_order_has_bookingserror) - Loading WooCommerce and WooCommerce Bookings in child theme function
- Copying some files from plugin into child theme and editing the
/woocommerce-bookings/order/admin/booking-display.phpandbooking-summary-list.phpfiles
I also tried taking all the code examples I found on SO and having GPT analyze and write a function but everything that produced too, was no good.
// Add custom column to WooCommerce admin orders page
function custom_add_booking_dates_column($columns) {
// Add the custom column after the 'order_actions' column
$columns['booking_dates'] = __('Booking Dates', 'text-domain');
return $columns;
}
add_filter('manage_edit-shop_order_columns', 'custom_add_booking_dates_column');
// Populate the custom column with data
function custom_booking_dates_column_content($column, $post_id) {
if ($column == 'booking_dates') {
// Retrieve booking dates for the order (replace this with your own logic)
$booking_dates = get_post_meta($post_id, '_booking_dates', true);
// Display the booking dates
echo esc_html($booking_dates);
}
}
add_action('manage_shop_order_posts_custom_column', 'custom_booking_dates_column_content', 10, 2);
add_action('after_setup_theme', 'child_theme_setup');
function child_theme_setup() {
// Load WooCommerce
add_theme_support('woocommerce');
// Load WooCommerce Bookings
add_theme_support('woocommerce-bookings');
}
// Add custom column to WooCommerce admin orders page
function add_custom_column_to_orders_page($columns) {
// Add a new column called "Booking Dates" after the "Order Total" column
$columns['booking_dates'] = __('Booking Dates', 'text-domain');
return $columns;
}
add_filter('manage_edit-shop_order_columns', 'add_custom_column_to_orders_page', 20);
// Populate custom column with Booking Start and Booking End dates
function populate_custom_column_content($column) {
global $post, $the_order;
if ($column === 'booking_dates') {
$order_id = $post->ID;
// Check if the order has booking data
if (wc_booking_order_has_bookings($order_id)) {
$booking_data = wc_get_order($order_id)->get_items('booking');
// Loop through each booking item (there may be multiple bookings in one order)
foreach ($booking_data as $item_id => $booking_item) {
$booking_start = date_i18n(wc_date_format(), strtotime($booking_item['Start']));
$booking_end = date_i18n(wc_date_format(), strtotime($booking_item['End']));
// Display Booking Start and End dates for each booking
echo '<strong>' . __('Booking #', 'text-domain') . $booking_item['Booking ID'] . '</strong><br>';
echo __('Start Date:', 'text-domain') . ' ' . esc_html($booking_start) . '<br>';
echo __('End Date:', 'text-domain') . ' ' . esc_html($booking_end) . '<br>';
}
} else {
echo __('No booking data', 'text-domain');
}
}
}
add_action('manage_shop_order_posts_custom_column', 'populate_custom_column_content');

For WooCommerce Bookings enabled plugin, to display booking items start/end dates in admin product list on a new column, use the following:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.
You will get something like: