do it simply - Help and Advice

How to create recurring boookings with Woocommerce

Lot’s of people love what Woocommerce Bookings can do, and many buy into the pretty expensive plugin before they realise some of limitations. I was one of them.

I had to learn pretty quickly that 2 of the most important features that my client wanted weren’t available out of the box with Bookings. The first was allowing customers to select the date first before seeing what they are able to book. You can see my write up to that selecting the date first, here.  The other big one is…

how to create a recurring booking

Woocommerce Bookings allows you to manually create a booking and this is where you start to create a recurring one.  From their website here is the basic code to create a booking programmically.

Now for many, this may just be enough to get you on your way, but some of us need a little more.  Below I will map out what I have done for my client.

I have modified the plugin to create 5, 6, or 7 week recurring bookings, this depends on the time of year.  These make up a course, I’m assuming same as what you are trying to do.  There is quite a lot of variability in the dates and resources for my version so I haven’t automated a huge amount yet (I am planning on it for a plugin).


My other main variable is that my system allows you to have different resource capacity on each of those recurring dates.  For instance Mar 18th might have 24 places and Mar 25th may have 32.  This was a specific client request, and makes what I’ve done a little more complicated.

Here are the basics.

1. Create a product that describes the course/classes (as I’ve done here).  No dates or anything are needed in the product itself, you will do this manually.  I suppose there is no reason you can’t supply a calendar here and use the selected date as the start of your bookings.  It wasn’t necessary for my version.

2. Create a bespoke plugin to work along side Woo Bookings. – You can do this in function.php but it can become really messy really soon.

3. Create a function to do the work that hooks into  the action ‘woocommerce_payment_complete’

4. The function will loop through the items in your completed order, if the item matches the course (product) id, then you will manually create your recurring bookings.

5.  Creating the manually bookings needs the following parameters, the product_id you are booking against, the start date, the number of weeks, and the resource_id (if used).

So, here is my seemingly complicated function, but if you read through it, it’s not too difficult to figure out.

Some things to note on my function.

a. I am manually entering the product and resource ids because these are constantly changing for my client.  You could create (and I will eventually) an admin bit to allow you to set these in the CMS.
b. Normally the resource id wouldn’t have to change per week you could use the same, again this is bespoke for my client.
c. My client has variations too, sometimes this is course level, sometimes it’s course length, so I have to check for this in my function too.
d. I have also added a check in this function to see if they have purchased a membership, if they have I add a coupon to their basket which gives them 20% off of their booking.

As I’ve previously mentioned, more of this can be automated or looped… I’m working on it.. 🙂

I’d like to hear what you’ve tried to do or got stuck on.  My ultimate goal is to write this into a plugin to help others.  To do this I would like more use cases.  So please send me a note.

Update: First plugin version available.

You can visit my Github repository for the first version of the recurring bookings plugin.  Please feedback how you get on.

Good luck!

 

Posted in Developers, For Business OwnersTagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *