Validating Appointment Date & Time When When Scheduling Appt

Hi,

I've made use of the great support provided in this thread :
Limiting the number of appointments per a month per user

To add a function that checks the current user's existing appointment count for a given date range, and returns an error if they've scheduled the maximum number already. I need to make two further tweaks to the function that require capturing the following variables:

1. The DateTime the user is trying to schedule an appointment for.
2. The duration of appointment they are trying to schedule.*

*If I'm able to get the variables for the event "Start Date Time" and "End Date Time" into the function, I can calculate the duration easily.

I've searched, but I don't see where/how to pass the appointment's start time and duration into variables within the function. Any solution or a point in the right direction would be much appreciated!

  • Panos

    Hi Brad Smith ,

    First thing you'll need to change is the way to get the appointments table, so instead of:
    $appointments->app_table
    you can use
    $appointments_table = appointments_get_table( 'appointments' );
    This way the query will be changed to:

    $appointments_table = appointments_get_table( 'appointments' );
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$appointments_table} WHERE user={$current_user->ID} AND status IN ( 'pending', 'confirmed', 'paid' ) AND start > ( NOW() - INTERVAL 30 DAY ) " );

    As for accessing the start and end we can use the $_POST var:

    $sent_vals = explode( ':', $_POST['value'] );
    	$location_id = (int)$sent_vals[0];
    	$service_id = (int)$sent_vals[1];
    	$provider_id = (int)$sent_vals[2];
    	$start = (int)$sent_vals[3];
    	$end = (int)$sent_vals[4];

    In order to get service duration you can use the service id that is also included in $_POST:

    $service = appointments_get_service( $service_id );
    $service_duration = $service->duration;

    If you find this confusing you can explain what you want to achieve so we could provide a more complete example :slight_smile:

    Thanks!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.