Last active
April 7, 2025 10:42
-
-
Save thisissandip/86062d23a331a4d19f5061b23fcc0818 to your computer and use it in GitHub Desktop.
booking-creation-logger: Logs details of the new booking in WooCommerce > status > logs
This file contains hidden or 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
/** | |
* Monitor new booking creation using wc_get_logger | |
*/ | |
function log_all_new_bookings( $booking_id ) { | |
if ( ! function_exists( 'get_wc_booking' ) ) { | |
return; | |
} | |
$booking = get_wc_booking( $booking_id ); | |
if ( ! $booking ) { | |
return; | |
} | |
$logger = wc_get_logger(); | |
$context = array( 'source' => 'bookings-creation-logger' ); | |
$log_data = array( | |
'Booking ID' => $booking_id, | |
'Product ID' => $booking->get_product_id(), | |
'Status' => $booking->get_status(), | |
'Start Date' => $booking->get_start_date(), | |
'End Date' => $booking->get_end_date(), | |
'Resource ID' => $booking->get_resource_id(), | |
'Persons' => $booking->get_persons(), | |
'All Day' => $booking->is_all_day() ? 'Yes' : 'No', | |
'Parent ID' => $booking->get_parent_id(), | |
'Created At' => current_time( 'mysql' ), | |
); | |
$log_message = "New Booking Created:\n" . print_r( $log_data, true ); | |
$logger->info( $log_message, $context ); | |
} | |
add_action( 'woocommerce_booking_in-cart_to_paid', 'log_all_new_bookings' ); | |
add_action( 'woocommerce_booking_unpaid_to_paid', 'log_all_new_bookings' ); | |
add_action( 'woocommerce_booking_confirmed_to_paid', 'log_all_new_bookings' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment