Prevent user from taking new appointment for 24 days after confirmed appointment

We have the following regulatory requirement:
Once a user takes an appointment with us, they have to wait for 24 days before they can schedule another appointment with the provider (ANY provider in the network)

Is there a way that this plugin can be updated to prevent user from taking new appointments for 24 days after they take a confirmed appointment?


  • vandana
    • Design Lord, Child of Thor

    Hi Predrag -
    I had tried that already. That rule is being applied only if the previous appointment is in 'Pending' status. We need this rule to be applied even if the last appointment is in Confirmed or Completed status.

    How do I do that?


  • Predrag Dubajic
    • Support

    Hey Vandana,

    I had a look at the plugin code and believe I have a solution but you will need to make small change in code.
    You will need to access your plugin files via FTP and open appointments.php file using some text editor like SublimeText, Notepad++ or similar.

    On line 1787 you will see this code:
    " WHERE created>'".$checkdate."' AND status='pending' AND (".$q.") " );
    Remove the "AND status='pending'" part or replace the line with this:
    " WHERE created>'".$checkdate."' AND (".$q.") " );
    Save the changes and upload the file to its original location.

    Let me know if this works for you.

    Best regards,

  • vandana
    • Design Lord, Child of Thor

    Hi Predrag -
    That almost worked.

    It let me create the appointment within a week the first time around but now it is giving me the message to wait.

    Even after 24 days, it won't let me create the appointment now.


  • vandana
    • Design Lord, Child of Thor

    Hi Ash

    Thank You for your response.

    Lets say the user took an appointment for Dec 30th on Dec 24th.

    The expectation is that the same user will not be able to schedule the next appointment till the date of Jan 23rd (Dec 30 + 24 days)

    The can actually schedule that appointment today Dec 25th but the appointment date has to be on or after Jan 23rd.

    Make sense?


  • Ash
    • WordPress Hacker

    Hello @vandana

    I hope you are well today.

    To do so, you must enable login required to book an appointment. Then you add the following code:

    // Works only if login required
    function limit_active_apps( $reply_array ) {
    	global $wpdb, $current_user, $appointments;
    	// Change statuses as required. i.e. remove pending condition if you wish
    	$start = $wpdb->get_var( "SELECT start FROM " . $appointments->app_table . " WHERE user=".$current_user->ID." AND (status='pending' OR status='confirmed' OR status='paid' )" );
    	$s_string = $reply_array['start'];
    	$s_string = explode( '</span>', $s_string );
    	$s_string = explode( '</label>', $s_string[1] );
    	$s_string = date_i18n( 'Y-m-d', strtotime( $s_string[0] ) );
    	$start = explode( ' ', $start );
    	$date1 = date_create( $start[0] );
    	$date2 = date_create( $s_string );
    	$diff = date_diff( $date1, $date2 );
    	$update = new DateTime( $start[0] );
    	$update->add( new DateInterval('P25D') );
    	if ( $diff->format( '%a' ) <= 24 )
    		return array( 'error' => 'You can not book an appointment before dated ' . $update->format( get_option( 'date_format' ) ) );
    	return $reply_array;
    add_filter( 'app_pre_confirmation_reply', 'limit_active_apps' );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.


  • vandana
    • Design Lord, Child of Thor

    Ash -

    You are awesome. I had to make some minor modifications to meet my messaging needs but the logic worked as expected.

    We'll now move into extended testing and let you know if we run into any issues.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.