Pending Appointments auto sync to calendar

Hi All,

In my site I have the option for clients to manually pay me at their appointment or pay in advance.

If they pay in advance via paypay this is fine the status of the appointment changes to paid and auto syncs with my google calendar.

If they choose manual payment (i.e pay me when I carry out the appointment) then the status remains pending and the appointment doesn't auto sync to my calendar. I've installed the add on I found in another thread which sends me an email for a pending notification. Which helps me change the status from pending to confirmed which then syncs the calendar.

But I think I would like all pending appointments to auto sync to my calendar. Or ideally have another status of "manual payment requested" which then also auto syncs to my calendar.

I'm using marketpress.

I hope that makes sense!

  • Vaughan

    Hi @kieran,

    Hope you're well?

    I've been looking through the code, this is certainly possible I believe, but it would be a hack, as I don't see a filter I can actually use.

    This would mean that it would be overwritten every time you update the plugin, so you would need to keep redoing the hack each time you update.

    But here's how.

    Open appointments.php

    Find the following function. (around line 1249)

    /**
    	 * Change status for a given app ID
    	 * @return bool
    	 */
    	function change_status( $stat, $app_id ) {
    		global $wpdb;
    		if ( !$app_id || !$stat )
    			return false;
    
    		$result = $wpdb->update( $this->app_table,
    									array('status'	=> $stat),
    									array('ID'		=> $app_id)
    					);
    		if ( $result ) {
    			$this->flush_cache();
    			do_action( 'app_change_status', $stat, $app_id );
    			if ( ($stat == 'paid' || $stat == 'confirmed') && is_object( $this->gcal_api ) )
    				$this->gcal_api->update( $app_id );
    			return true;
    		}
    		else
    			return false;
    	}

    then change the following line:

    if ( ($stat == 'paid' || $stat == 'confirmed') && is_object( $this->gcal_api ) )

    Replace with:

    if ( ($stat == 'paid' || $stat == 'confirmed' || $stat == 'pending' ) && is_object( $this->gcal_api ) )

    I haven't tested, but it should work, however i'm unsure of what will happen if the appointment is removed, whether it will be removed from GCal or not, I think it should do ok.

    Hope this helps

  • Kieran

    Hi Vaughan,

    I altered the code but it didn't seem to work.

    Then I noticed there was another piece of code

    -----------------

    // Add to GCal API
    if ( ('confirmed' == $status || 'paid' == $status) && is_object( $this->gcal_api ) )
    $this->gcal_api->insert( $insert_id );

    ----------> Changed to

    // Add to GCal API
    if ( ('confirmed' == $status || 'paid' == $status || 'pending' == $status) && is_object( $this->gcal_api ) )
    $this->gcal_api->insert( $insert_id );

    There was then another piece of code....

    -----------------

    // If confirmed or paid, add these to GCal
    else if ( 'paid' == $new_status || 'confirmed' == $new_status ) {
    foreach ( $_POST["app"] as $app_id )

    ----------> Changed to

    // If confirmed, pending or paid, add these to GCal
    else if ( 'paid' == $new_status || 'confirmed' == $new_status || 'pending' == $new_status ) {
    foreach ( $_POST["app"] as $app_id )

    Changed all those and finally started working. Does this look ok or have I done some damage! lol.

    Would it be possible to move to the features section and see whether we can have some kind of tick box in the settings where a user could select which kind of appointments would be synced to Gcal. The paid and confirmed could be pre ticked and then for users like me who want to sync pending appointments (as they have clients who pay at time of treatment) I could tick the pending box and this would work well.

    Removing an appointment works fine :slight_smile:

    Thanks for your help so far!

  • Vaughan

    Hi,

    The code changes look fine :slight_smile: If it's working, then you haven't caused any damage :slight_smile:

    I can certainly move this to the feature requests for the developer to consider in a future release, though it's not something i've seen requested previously, however the developers will look into it and consider it.

    Even if they decide not to add it as an actual option in the admin, they could certainly add a filter hook for it, so that in future you could place a filter/function in your theme functions.php to enable it, which would make it future proof on updates.

    Hope this helps

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.