Hankan - Multiple Provider Selection - Is it possible?

Hello I was wondering if it is possible to select multiple providers when scheduling an appointment. So in my case a parent has two children each with a different teacher and they would want to schedule appointments with each of those teachers in one swoop..

Thanks Scott

  • scdwb
    • Design Lord, Child of Thor

    Hi Hakan,

    Can you clarify how providers are selected when "no preference" is chosen? For example, how about if every time a user selects "no preference" is just so happens that all 10 providers are available for that time and day? How does the plugin choose?

    Is it random or maybe based on the providers ID?

    If it is not random and based on a linear factors, such as the ID, then it seems like one providers will get all the appointments over all the other providers until this favoured provider runs out of time slots. Ideally it would be random so in my example, all 10 providers will get a look in.

    Many thanks,
    Steven

  • scdwb
    • Design Lord, Child of Thor

    Hi Hakan,

    If the plugin does not pick any providers in this case, does this mean the plugin can become overbooked?

    As an example, what about if there was only 1 time slot available on Monday at 9-10am. And there were 2 providers available for these time slots, Provider A and Provider B.

    If User A books with no preference in the 9-10am slot. Then User B and User C books the 9-10am slot, each selecting Provider A and Provider B respectfully, what happens? As there is an extra time slot that has not been assigned to a provider yet, but now all the providers are unavailable as were specifically selected by the last two users.

    Steven

  • Hakan
    • The Incredible Smush

    Hi,

    I doesn't matter if you select a provider or not, plugin calculates who is exactly available for that time slot and who can give that service at that time.

    As an example, what about if there was only 1 time slot available on Monday at 9-10am. And there were 2 providers available for these time slots, Provider A and Provider B.

    If User A books with no preference in the 9-10am slot. Then User B and User C books the 9-10am slot, each selecting Provider A and Provider B respectfully, what happens?

    As there are only 2 providers available for that slot, after user B booked it (and we know that user A already booked), user C cannot book it any more. He will get a warning or he will see that time slot disabled.

    Is this a presales question? Sorry, I cannot see if you have already downloaded this plugin.

    If you have already downloaded it, you can check it yourself.

    From the FAQ:

    What happens if a client was applying for an appointment but at the same time another client booked the same time slot?
    Appointments+ checks the availability of the appointment twice: First when client clicks a free box and then when he clicks the confirmation button. If that time slot is taken by another client during these checks, he will be acknowledged that that time frame is not avaliable any more. All these checks are done in real time by ajax calls, so duplicate appointments are not possible.

    Cheers,
    Hakan

  • scdwb
    • Design Lord, Child of Thor

    Hi Hakan,

    Just a follow up which expands on my original question. My original question was asking what happens when no provider is selected. In this case the decision is left to the business owner.

    I need the plugin to automatically select an available provider. It would be great to have an option for the "no preference" option so we can choose for either the plugin to automatically select a random provider or the business own can decide (like it currently does).

    Is this possible?

    Many thanks,
    Steven

  • Hakan
    • The Incredible Smush

    Hi Steven,

    Add these codes inside function.php of your current theme:

    function assign_random_provider( $app_id ) {
    global $wpdb, $appointments;
    $a = $appointments;
    if ( !is_object($a) )
    return;
    // Get appointment
    $app = $wpdb->get_row( 'SELECT * FROM ' . $a->app_table. ' WHERE ID='.$app_id. ' ' );
    // Check if a provider is already assigned
    if ( !$app || 0 != $app->worker )
    return;
    // Find providers who can give this service
    $workers=$a->get_workers_by_service( $app->service );
    if ( !$workers || empty($workers) )
    return;
    // Randomize
    shuffle($workers);
    // Find timestamp
    $start = strtotime( $app->start );
    $end = strtotime( $app->end );
    // Check each worker for being busy or not working
    foreach ($workers as $worker){
    $apps = $a->get_reserve_apps_by_worker( 0, $worker->ID );
    $busy = false;
    if ( $apps ) {
    	foreach ( $apps as $_app ) {
    		if ( $start >= strtotime( $_app->start ) && $end <= strtotime( $_app->end ) ) {
    			$busy = true;
    			break;
    		}
    	}
    }
    if ( $busy || !$a->is_working($start,$end,$worker->ID))
    continue;
    // We found a free provider
    $result=$wpdb->update( $a->app_table, array('worker'=>$worker->ID),array('ID'=>$app_id) );
    if ( $result )
    wp_mail( $a->get_worker_email($worker->ID),'New appointment', 'You have been assigned a new appointment on '. mysql2date($a->datetime_format, $app->start));
    }
    }
    add_action( 'app_new_appointment', 'assign_random_provider' );

    Cheers,
    Hakan

  • scdwb
    • Design Lord, Child of Thor

    Thank you very much for this! :slight_smile:. I'll test it out and it will be perfect for what I need.

    Is this something you would include in the live plugin as an update? Having the option to remove the "provider select" from the front end and instead choosing to "randomly select a provider" as an option would be great.

    Steven

  • dan_beil
    • New Recruit

    Hi I have a similar question to this thread. I am looking to add addition providers to one appointment. I my case there will be one client with up to 5 providers. I have duplicated the provider box, created an additional database table (app_workers2) though can't seem to get the additional drop down to save it's value (I am getting the 'Record could not be saved OR you did not make any changes!' error). any help on where to tell the plugin to save this value would be great. Thanks.

  • dan_beil
    • New Recruit

    Thanks Hakan,

    I was guessing that I was going about this the wrong way. A very short example of a hook to create anything in the spot that I need it (below the 'provider' box) would be appreciated if you have the time.

    I am most familiar with add_metaboxes if that is an option here.

    -
    Dan

  • Hakan
    • The Incredible Smush

    Hi Dan,

    Why do you need a second provider dropdown there in the first place? Suppose that you added that. What are you planning to do with that field? Plugin does not have any functions that support that field.

    So please explain what you are trying to achieve as a final result.

    Cheers,
    Hakan

  • dan_beil
    • New Recruit

    Hi Hakan,

    the purpose of the field is to allow more than one (up to 5) 'providers' for each appointment.

    I am wondering if I can (jQuery) apend or prepend a custom post type to this field though there does not seem to be a unique ID or CLASS to the 'provider' drop down (from memory).

    In the end all 'providers' will be emailed reminders, show up on the calender, i.e. fully functional with what the stalk appointments + provides.

    -
    D

  • Hakan
    • The Incredible Smush

    Hi Dan.

    I think you should elaborate what happens after you select 5 providers. Can you be more specific and give a real life example for this?

    It may be quite simple to choose 5 providers, and it is maybe 1% of the whole process, but what happens next is more important. Because selection is one thing, handling the schedules (who is available at what time for which service) is the most important thing.

    Cheers,
    Hakan

  • dan_beil
    • New Recruit

    Hi Hakan,

    At this point I am not worried about overlapping schedules or anything else (admin's will be taking care of this). We already have in place the code to create user accounts and profiles (CPT's) and are looking for an independent solution for a visual representation and email notification.

    The real life example is that when a physically impaired individual signs up to do a physically challenging activity they will have between 2 and 5 'providers' with them.

    All I need appointments + to do is allow 2-5 'providers' (and eventually email them notifications, which I should be able to take care of once the save aspect of the additional fields is taken care of).

    After thinking more about this I may be able to pull of a jQuery / ajax / php solution but your thoughts are always welcome.
    -
    Dan

  • dan_beil
    • New Recruit

    eventually, right now I am just seeing if appointments + will work for my application. if you can point me in the right direction with one or two filter / hook examples that would be great. if not I will continue to research this and other solutions.

  • Hakan
    • The Incredible Smush

    Hi Dan,

    Sorry but I see no hooks that fits to your case with that limited information you have provided.

    A+ is a free plugin: You can use it anyway you wish, provided that you confirm GNU public license.

    So, you are free to create a plugin of your own based on A+, but we cannot support this.

    Cheers and take care,
    Hakan

  • scdwb
    • Design Lord, Child of Thor

    Hi Hakan,

    I thought the assign_random_provider() function you wrote above worked perfectly but there seems to be a problem.

    I have two providers available for the same timeslots. When making an appointment for say timeslot A then this function automatically assigns a Provider correctly.

    However, if a customer then selects the same timeslot, where the other provider is available, for some reason this function doesn't automatically assign the remaining provider. It instead defaults to "Our Staff".

    I think maybe the problem is coming from this line:

    if ($a->is_busy($start,$end,$worker->ID) || $a->is_break($start,$end,$worker->ID))

    I'm not sure but does the is_busy() check specifically against the worker? Doesn't this function check against the timeslot instead and not the work? I may be wrong about this but I can't seem to find what the problem may be. Both providers are available for the times slots I'm testing against. The first time a timeslot is booked it always automatically assigns a provider correctly. It's when the timeslot is chosen again, and even though there is a second provider available, it defaults to "our staff".

    Many thanks,
    Steven

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.