• Resolved bhwarrior

    (@blackhatwarrior)


    Hi again,

    Is it possible to add an order note when customer cancel or reschedule their bookings? This will help admins to follow up actions taken by the customer.

    I.e.
    “Customer Name” has cancelled booking number “1234”.
    “Customer Name” has rescheduled booking number “1234” from “old date & time” to “new date & time”.

    Thank You!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Booking Activities Team

    (@bookingactivities)

    Hello,

    Thank you for your request,

    This feature is not implemented but it’s a good idea, I add it to the development schedule.

    You can do it with the API, but it requires development skills.

    Regards,
    Yoan Cutillas

    Thread Starter bhwarrior

    (@blackhatwarrior)

    Thank you for adding my request to the development schedule. Can you please provide a temporary solution?

    Plugin Author Booking Activities Team

    (@bookingactivities)

    Hello,

    You can use these functions in your child theme functions.php:

    // Keep a log when a booking status changes
    function my_theme_log_booking_status_changes( $booking_id, $state, $args ) {
    	$who		= isset( $args[ 'is_admin' ] ) && ! $args[ 'is_admin' ] ? 'customer' : 'administrator';
    	$message	= 'Booking #' . $booking_id . ' status changed to ' . $state . ' by ' . $who;
    	my_theme_add_log( $message );
    }
    add_action( 'bookacti_booking_state_changed', 'my_theme_log_booking_status_changes', 10, 3 );
    
    // Keep a log when a booking group status changes 
    function my_theme_log_booking_group_status_changes( $booking_group_id, $state, $args ) {
    	$who		= isset( $args[ 'is_admin' ] ) && ! $args[ 'is_admin' ] ? 'customer' : 'administrator';
    	$message	= 'Booking group #' . $booking_group_id . ' status changed to ' . $state . ' by ' . $who;
    	my_theme_add_log( $message );
    }
    add_action( 'bookacti_booking_group_state_changed', 'my_theme_log_booking_group_status_changes', 10, 3 );
    			
    
    // Keep a log when a booking is rescheduled
    function my_theme_log_booking_reschedules( $booking, $old_booking, $args ) {
    	$who		= isset( $args[ 'is_admin' ] ) && ! $args[ 'is_admin' ] ? 'customer' : 'administrator';
    	$date_format= bookacti_get_message( 'date_format_long' );
    	$old_start	= bookacti_format_datetime( $old_booking->event_start, $date_format );
    	$new_start	= bookacti_format_datetime( $booking->event_end, $date_format );
    	$message	= 'Booking #' . $booking->id . ' was rescheduled from ' . $old_start . ' to ' . $new_start . ' by ' . $who;
    	my_theme_add_log( $message );
    }
    add_action( 'bookacti_booking_rescheduled', 'my_theme_log_booking_reschedules', 10, 3 );
    
    // Add a line in the log file
    function my_theme_add_log( $message ) {
    	$file	= WP_CONTENT_DIR . '/uploads/bookings-actions.log'; 
    	$handle	= fopen( $file, 'a' );
    	$write	= 0;
    	if( $handle !== false ) {
    		$time = date( 'c', time() );
    		$log = $time . ' - ' . $message . PHP_EOL;
    		$write	= fwrite( $handle, $log );
    		fclose( $handle );
    	}
    	return $write;
    }

    It will write a log in a file that you can access in your browser at:
    yoursite.com/wp-content/uploads/bookings-actions.log
    each time a booking status changes or a booking is rescheduled.

    Then, with CTRL+F you can look for “Booking #102” to find the logs related to the booking ID 102.

    Regards,
    Yoan Cutillas

    Thread Starter bhwarrior

    (@blackhatwarrior)

    For me it’s important to add an order note instead of logs. I managed to get it done after some tweaking:

    I wonder why $booking is not an object sometimes:
    if( ! is_object( $booking ) ) { $booking = bookacti_get_booking_by_id( $booking ); }

    Need to know when rescheduled event starts not when it ends:
    $new_start = bookacti_format_datetime( $booking->event_start, $date_format );

    This is how I’m adding order notes:

    $order_id = bookacti_get_booking_order_id( $booking->id );
    $order = wc_get_order( $order_id );
    $order->add_order_note($message);

    Thanks for the awesome support!

    Plugin Author Booking Activities Team

    (@bookingactivities)

    Hello,

    Sorry for the mistakes.
    $booking will always be an object in the next versions, I have made the code with my development version.

    Indeed you can add order notes this way, I haven’t thought about it in the first place, nice!

    Regards,
    Yoan Cutillas

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add an order note when booking gets cancelled or rescheduled’ is closed to new replies.