Appointments+ >> add new manual appointment recurring

Hi WPMU DEV Team!

Thanks for the great Appointments+ Plugin: reasonable priced, powerful and chic :slight_smile:
I love the Google Calender integration.

I have found several suggestions regarding recurring appointments but none was "so easy as mine" :wink: So I'll give it a try:

What I'm desperately missing is the posibility to add recurring appointments (from the admin area, not as customer).
I understand the problems with recurring payments. But I´m not using Paypal - we're renting seminar rooms which are payed in cash ...

I tried to use Gcal for recurring bookings but I can't pass the information from Gcal to A+ which service or service provider in A+ should be booked.

I think without payment that can be implemented straigth forward (see attachment).

One example: we have a customer that books every thursday and wednesday for the next 12 weeks (which would lead to "painful" 24 manual bookings :wink:)

Thanks for your help!

  • aristath

    Hello there @Thomas and welcome to the WPMUDEV Community!

    The Appointments+ plugin was build from the ground up for one-time appointments. That's what makes your request for supporting recurring appointments really hard...
    Perhaps Appointments is not exactly what you need... Events+ is a plugin that might suit your needs better, I suggest you take a look at that: https://premium.wpmudev.org/project/events-plus/

    I hope that helps!

    Cheers,
    Ari.

  • Thomas

    Hi Ari,
    thanks for your reply.

    Events doesn't work for us.

    I'm not so sure if its really so hard to implement ...

    The algorithm is quite simple to describe for the "Add new" Appointment UI:

    don't just save/update the data but start a loop that uses identical entries except for date/time which will be incremented.

    Thats exactly what I would have to do (as I heard today) for about 100 times (same time Monday+Tuesday every week for at least one year ...) manually.

    Why not let php do the loop for me?

    (btw. if had better php knowledge I would implement it myself to function inline_edit_save in appointments.php; I think one of your skilled programmers would need just 2 or 3 hours for UI and algorithm)

    Thanks for your help!
    Thomas

  • aristath

    Hello again @Thomas,
    It's not like the developers are bored or unwilling to implement this... They work really hard to make the plugin as extensible as possible!
    Your logic is sound for simple post types, however the structure of an appointment is not the same as any other post, you can't simply "loop" it!

    I have marked this as a feature request and notified the plugin developer about it.
    If there's any way to accomplish this he'll let us know on this post.

    Cheers,
    Ari.

  • Thomas

    Hello again,
    sorry if that sounded as if I'd think 'the developers are bored or unwilling' ...

    I tried to hack some php - please be patient with me (I'm not into php) - and the test suceeded with the following code for generating 3 appointments weekly (else part replaced in appointments.php line 8737):

    else {
    // Insert
    //
    // for testing without GUI integration:
    $recurring = true;
    $recurring_step = '1 week';
    $recurring_count = 3;

    $shall_we_continue = false;
    $loop_count = 1;
    do
    {
    $insert_result = $wpdb->insert( $this->app_table, $data );
    if ( $insert_result && $resend )
    $this->send_confirmation( $wpdb->insert_id );
    if ( $insert_result && is_object( $this->gcal_api ) )
    $this->gcal_api->insert( $app_id );
    if ( $recurring ) {
    $data['start'] = date("Y-m-d H:i:s", strtotime($data['start'].'+'.$recurring_step));
    $data['end'] = date("Y-m-d H:i:s", strtotime($data['end'].'+'.$recurring_step));
    $loop_count++;
    }
    }while ($loop_count <= $recurring_count);
    }

    And that was done quite quickly (most time spent on google for php syntax) - that was meant by my posting before - a wpmu developer could surely have done that in 5 minutes ...

    So maybe this (probably bad) code could be a starting point ...

    Thanks for your considerations!

    Thomas

  • Thomas

    Sorry - just saw that I forgot to format the code:

    else {
    			// Insert
    			//
    			// for testing without GUI integration:
    			$recurring = true;
    			$recurring_step = '1 week';
    			$recurring_count = 3;
    			//
    
    			$loop_count = 1;
    			do
    			{
    				$insert_result = $wpdb->insert( $this->app_table, $data );
    				if ( $insert_result && $resend )
    					$this->send_confirmation( $wpdb->insert_id );
    				if ( $insert_result && is_object( $this->gcal_api ) )
    					$this->gcal_api->insert( $app_id );
    				if ( $recurring ) {
    					$data['start'] = date("Y-m-d H:i:s", strtotime($data['start'].'+'.$recurring_step));
    					$data['end'] = date("Y-m-d H:i:s", strtotime($data['end'].'+'.$recurring_step));
    					$loop_count++;
    				}
    			}while ($loop_count <= $recurring_count);
    		}
  • pxwm

    Hi @Thomas,

    I would suggest the main area of complexity is if you are attempting to book a recurring appointment for a time slot that is not available.
    This would either mean the appointment would fail or you would have to include a rule to decide what action to take if the time slot was not available.

    Further complexity relates to if the recurring appointments are for a different service and/or service provider so not an easy development.

    Regards
    SteveB

  • Thomas

    Hi @pxwm,

    thanks for your looking into the matter and your answer!

    Sure, but I can - with the current plugin version - do a manual single appointment "on top" of another already existing - and there's no error.

    Thats little evil compared to 100 manual bookings :wink:

    NOW I'd sense some resistance against developing this - from my point of view - easy feature.

    As I see it its quite easy: the user selects the service and service provider and all fills all the other fields - and can then create a series of appointments with exactly that settings but different dates/times.

    And if there's a collision - the plugin can print an error - telling the user that "appointment for DATE could not be created".

    I'd love to hear how all the other users asking for recurring appointments think about it - maybe I should take the time to look for them and contact them - let's see if I can find the time ...

    Either way - thanks for answering and have fun!

    Regards
    Thomas

  • pxwm

    Hi @Thomas,

    Many thanks for the further info and I agree you can double book from A+ admin but obviously this is not ideal as this is going to cause client issues.

    I can confirm you can book recurring appointments if you sync to your google calendar.
    However checking this out there are some limitations to the rules but as long as the appointment is for the same day/time then it looks as though you can create recurring appointments.
    Also if you wanted to book for a specific service provider you would have to create a google calendar for each service provider then create a unique GCAL api key for each service provider and change the relevant settings in the A+ 'GCAL' tab and in each Wordpress user profile
    Then making an appointment directly in your google calendar would reserve a slot in A+.
    Not sure how GCAL or A+ would handle unavailable time slots though.
    Also making A+ appointments through GCAL will place them in the 'Reserved by GCAL' which means you would have to login to A+ admin and go into each individual appointment and select a service and approve them all but this may be less painful than having to each appointment manually.

    I hope this helps
    Regards
    SteveB

  • Thomas

    Hey there at wpmu dev!

    I did my best to code it myself - I urgently needed it :wink:

    I'll share the code so maybe it could be an inspiration ...

    I added the following code snippets to appointments.php:

    In function myapps I had to add the new fields for recurring bookings (replace line 7960 with the following javascript for "data"):

    var recurringamount = save_parent.find('select[name="recurringamount"] option:selected').val();
    					var recurringstep = save_parent.find('select[name="recurringstep"] option:selected').val();
    					var recurringtimes = save_parent.find('select[name="recurringtimes"] option:selected').val();
    					var data = {action: 'inline_edit_save', user:user, name:name, email:email, phone:phone, address:address,city:city, service:service, worker:worker, price:price, date:date, time:time, note:note, status:status, resend:resend, recurringamount:recurringamount, recurringstep:recurringstep, recurringtimes:recurringtimes, app_id: app_id, nonce: '<?php echo wp_create_nonce() ?>'};

    The GUI Part (after "confirm"/"Send confirmation email" in the "Add New" Appointment form) is inserted before line 8354 (function inline_edit):

    /* Recurring */
    		$intervals = array('nonrecurring', 'hours', 'days', 'weeks', 'months');
    		$html .= '<label>';
    		$html .= '<span class="title">'.__('Recurring every', 'appointments'). '</span>';
    		$html .= '<span class="input-text-wrap">';
    		$html .= '<select name="recurringamount">';
    		for ($i = 1; $i <= 90; $i++) {
    			if ( $i == 1 )
    				$sel = ' selected="selected"';
    			else
    				$sel = '';
    			$html .= '<option value="'.$i.'"'.$sel.'>'. $i . '</option>';
    		}
    		$html .= '</select>';
    		$html .= '<select name="recurringstep">';
    		foreach ( $intervals as $interval ) {
    			if ( $interval == 'nonrecurring' )
    				$sel = ' selected="selected"';
    			else
    				$sel = '';
    			$html .= '<option value="'.$interval.'"'.$sel.'>'. $interval . '</option>';
    		}
    		$html .= '</select>';
    		$html .= '<br /> for ';
    		$html .= '<select name="recurringtimes">';
    		for ($i = 1; $i <= 99; $i++) {
    			if ( $i == 1 )
    				$sel = ' selected="selected"';
    			else
    				$sel = '';
    			$html .= '<option value="'.$i.'"'.$sel.'>'. $i . '</option>';
    		}
    		$html .= '</select>';
    		$html .= ' times.';
    		$html .= '</span>';
    		$html .= '</label>';

    And finally replace the else part in function inline_edit_save (line 8467 to 8492):

    else {
    			// Insert
    			//
    			$recurring = false;
    			$recurringcount = 0;
    			if ($_POST['recurringstep'] != 'nonrecurring') {
    				$recurring = true;
    				$recurringinc = '+'.$_POST['recurringamount'].' '.$_POST['recurringstep'];
    				$recurringcount = $_POST['recurringtimes'];
    			}
    			//
    			$loop_count = 1;
    			do
    			{
    				$insert_result = $wpdb->insert( $this->app_table, $data );
    				if ( $insert_result && $resend )
    					$this->send_confirmation( $wpdb->insert_id );
    				if ( $insert_result && is_object( $this->gcal_api ) )
    					$this->gcal_api->insert( $app_id );
    				if ( $recurring ) {
    					$data['start'] = date("Y-m-d H:i:s", strtotime($data['start'].$recurringinc));
    					$data['end'] = date("Y-m-d H:i:s", strtotime($data['end'].$recurringinc));
    				}
    				$loop_count++;
    			}while ($loop_count <= $recurringcount);
    		}

    If anybody needs the complete appointments.php (for plugin version 1.4.1) feel free to contact me!
    The working page can be found at http://www.freilicht.org/mietpreise/raum-gruen-mieten/ (every Monday and Tuesday is booked for around 50 weeks :slight_smile: starting April 2014).

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.