Created
November 7, 2023 08:00
-
-
Save Qubadi/af9753eae713ee66b3039279b6073902 to your computer and use it in GitHub Desktop.
Jetbooking + Woocommerce, display check in and check out orders my account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_check_in_out_column_title($columns) { | |
$new_columns = array(); | |
foreach ($columns as $key => $name) { | |
$new_columns[$key] = $name; | |
if ('order-number' === $key) { | |
$new_columns['order-check-in-out'] = 'Check in / out'; | |
} | |
} | |
return $new_columns; | |
} | |
add_filter('woocommerce_account_orders_columns', 'add_check_in_out_column_title'); | |
function display_check_in_out_dates($order) { | |
global $wpdb; | |
$order_id = $order->get_id(); | |
// Fetching the dates based on the order ID | |
$dates = $wpdb->get_results( | |
$wpdb->prepare( | |
"SELECT im.meta_key, im.meta_value | |
FROM {$wpdb->prefix}woocommerce_order_itemmeta AS im | |
JOIN {$wpdb->prefix}woocommerce_order_items AS oi ON im.order_item_id = oi.order_item_id | |
WHERE oi.order_id = %d AND (im.meta_key = '__jet_booking_check_in_date' OR im.meta_key = '__jet_booking_check_out_date')", | |
$order_id | |
), ARRAY_A | |
); | |
$check_in_date = ''; | |
$check_out_date = ''; | |
foreach ($dates as $date) { | |
if ($date['meta_key'] === '__jet_booking_check_in_date') { | |
$check_in_date = ' ' . date("d/m/Y", $date['meta_value']); | |
} elseif ($date['meta_key'] === '__jet_booking_check_out_date') { | |
$check_out_date = ' ' . date("d/m/Y", $date['meta_value']); | |
} | |
} | |
echo esc_html("{$check_in_date} | {$check_out_date}"); | |
} | |
add_action('woocommerce_my_account_my_orders_column_order-check-in-out', 'display_check_in_out_dates'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great