Web Analytics

The Events Calendar: Implementing Tickets and RSVPs for Recurring Events

by Utsab Karki, Senior WordPress Developer

Photo by Towfiqu Barbhuiya via Unsplash

With more than 46 million downloads and 800,000+ active installations, The Events Calendar is one of the most widely used plugins for displaying events on a WordPress website.

The free version of the plugin provides a number of different views for the calendar (month, list and day), the ability to assign Venues and Organizers, as well as a gallery of template tags, hooks and filters for customization. It also implements structured data for events, which can help with SEO and rich results in search engines.

There is also a library of extensions and add-ons available that further extend the plugin’s functionality. One of the add-ons, The Events Tickets, enables you to add tickets and RSVPs to events. While this add-on is great for adding tickets and RSVPs to single events, it currently does not support recurring events.

So if you need to add tickets or RSVPs to a recurring event – say, an event that takes place from 9am to 5pm on weekends for a month – then you would have to create a single event for each day and add the tickets or RSVPs to it.

Before we jump to the solution, let’s first try and understand what the issue is and why the plugin does not support recurring events out of the box.

The Problem: How Events are Implemented

The developers for the Event Tickets add-on did not intentionally skip implementing support for recurring events. The issue arose because of how recurring events are implemented by The Events Calendar plugin.

When a ticket is added to an event and the Save Ticket button is clicked, the ticket is associated with the current event’s ID even before the event is published. When a recurring event is created in the admin and the Publish button is clicked, a few different things happen.

First, the plugin will create single events (instances) based on the recurrence rule that has been added. Since version 6.0, the events will be part of a Series with the same name as well. But since each instance of the recurring event has a different ID, the ticket will only be associated with the first event.

The other issue with the Tickets add-on and recurring events is that each recurring event may have different configuration needs for the tickets. For example, some weekends the capacity for the ticket may be 20 while for others it may be 30. While we still do not have a solution for this issue, we do have a workaround for it which we will get into later.

The Solution: Checking for Custom Recurrence Rules

First, we need to be able to add recurrence rules and tickets to events and display them on the calendar based on the recurrence rule. Currently, as soon as you start adding a recurrence rule to an event, the field to create tickets or RSVP for the event is removed and a message is displayed stating that tickets are not supported on recurring events. Similarly, if you add a ticket to an event, the recurrence rules are hidden displaying the same message.

In order to overcome the issue, we will have to create custom meta boxes in the admin using add_meta_box or use a plugin such as Advanced Custom Fields to define the recurrence rules. For this example, using one of the methods, we will create radio buttons in the admin for if the event takes place weekly, on weekdays only, or on weekends only between the Start Date and the End Date defined for the event. Based on the user selection in the admin, we will return the values ‘weekly’, ‘weekdays’, and ‘weekends’ respectively.

Based on the calendar views that you have enabled for the calendar, you will have to update the respective templates. For month view and week view, you will have to update the multiday-event.php template inside the respective view folder. For others, it will be the event.php template inside the respective view folder. By now, you should know that you should not be making changes to the plugin files itself as that may get overridden when the plugin is updated. Use this link to learn how to get started making customizations to The Events Calendar.

Once we have the correct template, we want to add a check to the top of the event for the recurrence rules and only display the event on the calendar if it meets the criteria.

 $show_this_event = true;
 $event_repeats = { Get recurrence rule. }
 if ($event_repeats == 'weekly') :
    $event_start_day = $event->dates->start_display->format('D');
    $curr_day = date_format(date_create($day), 'D');
    if ($event_start_day != $curr_day) :
       $show_this_event = false;
    endif;
 elseif ($event_repeats == 'weekdays' || $event_repeats == 'weekends') :
    $curr_day = date_format(date_create($day), 'D');
    $week_days = $event_repeats == 'weekdays' ? array('Mon', 'Tue', 'Wed', 'Thu', 'Fri') : array('Sat', 'Sun');
    if (!in_array($curr_day, $week_days) :
       $show_this_event = false;
    endif;
 endif;

In the above code, we set $show_this_event to true as we want to display multi-day events that do not have the custom recurrence rule added. Then we get the recurrence rule and save it in $event_repeats.

If this is a ‘weekly’ event, then we need to only display this event on the same day of the week as the event’s start date. To do so, we save the day of the week the event start date is set to in $event_start_day, which can be accessed via the $event object. Then we save the current day of the week in the calendar in $curr_day and set $show_this_event to false if the $event_start_day variable is not equal to $curr_day.

Similarly for ‘weekdays’ and ‘weekends’ events, we check the current day of the week in the calendar saved in $curr_day against an array containing weekdays or weekends and set $show_this_event to false if the current day is not in the respective array.

Then we simply add a check to see if $show_this_event is set to true and process the rest of the template only if it is true.

The above solution resolves the issue of displaying recurring events in the calendar correctly even if they have tickets. Currently, we do not have a permanent solution to resolve the issue where the ticket capacity may be different for each recurring event or even the price.

There are a few workarounds for this, however. We can either update the ticket for the same event after each event has passed to match the capacity or price for the next upcoming event. Or we can add multiple tickets to an event for each date the event is recurring on and titles to the ticket with the date for clarification.

Hopefully The Events Calendar team will soon release an update to support tickets in recurring events, but for the time being, the above solution works great. You can create recurring events and still be able to add tickets to it and display them correctly on the front-end for users.

If you need help implementing tickets on recurring events, then reach out to us and we’d be more than happy to assist you in your web development and digital marketing needs.

Avatar photo
About Utsab Karki

Utsab Karki is the Senior WordPress Developer at Digital Ink. He builds new websites, manages functionality requests and changes, and makes clients' sites run better. Digital Ink tells stories for forward-thinking businesses, mission-driven organizations, and marketing and technology agencies in need of a creative and digital partner.

Other Stories You May Like

What’s your story?

Let’s share it with the world.

Let’s Do This

Close Window
All the Cool Kids are Doing it

Sign Up for the Digital Ink Newsletter

All the cool kids are doing it.