STATUS ÜBERPRÜFEN
I AM LISTENING TO
|

WooCommerce Appointments Enhanced with an Availability Calendar

21. März 2018
.SHARE

Table of Contents

WordPress WooCommerce Appointments

WooCommerce Appointments is a commercial  booking plugin that allows you to setup appointments with WooCommerce. It has full integration into Google calendar to track appointments of your staff.

Staff availability can be set globally or via each staff members profile. While this is nice, I was looking for an option to actually handle availability via another Google Calendar as well. That was a must have feature for a current project.

What do you do, if that feature is not available yet ? You poke the code!

The magic entry point for the staff availability is the user meta „_wc_appointment_availability„, which is made available through includes/class-wc-product-appointment-staff.php.

A couple of weeks ago I asked support for a simple filter hook to alter the availability on demand from the outside.

The development team added the feature in one of the latest releases, making wc_appointments_staff_availability the entry point for my custom availability changes.

The filter hook

add_filter( 'wc_appointments_staff_availability', 'availability_callback', 10, 3 );

function availability_callback($availability, $staff){
// Your changes here
return $availability;
}

Getting the data

You can either pull Google Calendar Events directly through the Google Calendar API or use the available iCal export option. In this quick example I will use the private calendar iCal export file.

The availability calendar

Lets setup a quick clean calendar, called „Availability“. So simple and catchy :)

  1. Create a new calendar
  2. Create some test events. WooCommerce Appointments supports multiple availability rules, but I am focusing on the time:range option and recurring events for this example. I might be extending on this a bit more in the future ! So for this example:  Friday, timeframe 10:00 – 16:00 and repeating four times.
  3. Go into settings and get the link to the privat ical export file

Parse iCal data

For this example I am using the PHP ICS Parser, but any other parser will do.  Install it via composer: composer require johngrogg/ics-parser.

Lets create a quick little plugin to get us going and save it to /wp-content/plugins/CustomAvailability/smile.php

<?php
use ICal\ICal;

/*
Plugin Name: WooCommerce Appointments - Custom Availability
Plugin URI: https://news.portalzine.de
Description: Attach additional Google Calendar for staff availability
Version: 1.0
Author: portalZINE NMN
Author URI: https://news.portalzine.de
*/


require_once(PATH_TO_VENDOR_DIR."vendor/autoload.php");

class StaffCustomAvailability{
 
function __construct() {
  add_filter( 'wc_appointments_staff_availability', array($this, 'staffAvailability'), 10, 3 );
 }
 
function staffAvailability($availability, $staff){
// Your changes here
return $availability;
}

}

$StaffCustomAvailability = new StaffCustomAvailability();

 

Set the availability

Its time to get the data into the system. I am only pulling and altering the availability for one single user in this example, the user with the USERID „3“. This should provide you with a good starting point.

function staffAvailability($availability, $staff){

// $staff holds the complete user data
// $availability is the current set of rules

// Only altering availability for  USERID 3

if($staff->data->ID == 3){
     $newSet = array();  
  try {
    // add the private ics file here
    $ical = new ICal('URL TO PRIVATE ICS FILE', array(
        'defaultSpan'                 => 2,     // Default value
        'defaultTimeZone'             => 'Europe/Berlin',
        'defaultWeekStart'            => 'MO',  // Default value
        'disableCharacterReplacement' => false, // Default value
        'skipRecurrence'              => false, // Default value
        'useTimeZoneWithRRules'       => false, // Default value
    ));

     } catch (\Exception $e) {
    die($e);
}

   $forceTimeZone = true;
        
   $events = $ical->sortEventsWithOrder($ical->events());
    // looping through all events
   foreach ($events as $event) {
        // Get Start and end date / time information
        $dtstart = $ical->iCalDateToDateTime($event->dtstart_array[3], $forceTimeZone);
        $dtend = $ical->iCalDateToDateTime($event->dtend_array[3], $forceTimeZone);
        
        // Define new time:range rule
        // Adding one rule per day 
       // Added Friday to the calendar + event recurring  4 times, which results in 4 new rules for staff member 3
        $newSet[] =  array(             
            'type' => "time:range",// rule type used for this example
            'appointable' => "yes",
            '[priority' => 10,
            'from' => $dtstart->format('H:i'), // start time 10:00
            'to' => $dtend->format('H:i'), // end time 16:00
            'from_date' => $dtstart->format('Y-m-d'), // start date -  Friday
            'to_date' => $dtend->format('Y-m-d') // end date - Friday
                       );
            $availability = $newSet;
          }
      
      
    }
return $availability;
}

The example pulls and parses the ics file on every load, use a transient or REDIS to store data and only refresh in certain intervals.

Hope this gets you started! I build a simple interface around it, with a lot of more rule options. This makes the setup for each staff member a brise. Now each of them can setup a calendar easily and provide  me with the ics link  :) WooCommerce Appointments rocks …

Enjoy coding ….

Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

This is my own task / project / workflow solution fully integrated into WordPress, which I began developing in 2025. After the recent cloud outages—and following a significant investment in the Asana ecosystem—I decided to build a robust, self-hosted WordPress solution featuring an almost complete Asana Sync API integration. I don’t have plans to make […]

UPDATED: Asana is a great project management tool, but for those who prioritize data privacy, control, and customization, self-hosted alternatives are a better option. In 2026, there are several robust and feature-rich self-hosted project management tools that can effectively replace Asana while giving you full control over your data. Here’s a look at some of […]

Inspired byGutenberg Blocks in Gravity Forms: Seamless Widget IntegrationGutenberg Blocks in Elementor: Seamless Widget IntegrationMeet the Isolated Block Editor – Gutenberg, Untethered – Integrated into Elementor The idea took over Once you start working on an idea its hard not to see all the other possibilities ;) The plugin automatically detects and replaces TinyMCE textareas […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs


I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.