• Resolved bhwarrior

    (@blackhatwarrior)


    Hello, Just like “Cancel” button disappears once the booking has been cancelled from orders/bookings page I want to hide “Reschedule” button once the booking is rescheduled to a new date successfully. Is it possible?

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

    (@bookingactivities)

    Hello,

    Yes you can, thanks to Booking Activities API.

    Add this code in your child theme functions.php:

    /**
     * Allow to reschedule only once
     * @param boolean $is_allowed
     * @param int $booking_id
     * @return boolean
     */
    function my_theme_allow_to_reschedule_once( $is_allowed, $booking_id ) {
    	if( ! $is_allowed || current_user_can( 'bookacti_edit_bookings' ) ) { return $is_allowed; }
    	
    	$reschedule_date = bookacti_get_metadata( 'booking', $booking_id, 'reschedule_date', true );
    	if( $reschedule_date ) { return false; }
    	
    	return $is_allowed;
    }
    add_filter( 'bookacti_booking_can_be_rescheduled', 'my_theme_allow_to_reschedule_once', 20, 2 );
    
    /**
     * Keep a record when a booking is rescheduled
     * @param int $booking_id
     * @param array $booking
     * @param array $args
     */
    function my_theme_save_reschedule_date( $booking_id, $booking, $args ) {
    	if( current_user_can( 'bookacti_edit_bookings' ) ) { return; }
    	bookacti_update_metadata( 'booking', $booking_id, array( 'reschedule_date' => date( 'Y-m-d H:i:s' ) ) );
    }
    add_action( 'bookacti_booking_rescheduled', 'my_theme_save_reschedule_date', 20, 3 );

    Regards,
    Yoan Cutillas

    Thread Starter bhwarrior

    (@blackhatwarrior)

    Thank You!

    Thread Starter bhwarrior

    (@blackhatwarrior)

    This code has stopped working since after recent update. When I echo $booking_id it gives me an object instead of booking ID. Any solution?

    Plugin Author Booking Activities Team

    (@bookingactivities)

    Hello,

    Yes, replace $booking_id with $booking->id in the first function only.

    Regards,
    Yoan Cutillas

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disallow users to reschedule a booking more than once’ is closed to new replies.