Users can add your events to their personal calendars with The Events Calendar. But what if you’d also like the ability to add those calendar links to your ticket emails with Event Tickets and Event Tickets Plus?

Although this feature isn’t quite available out of the box, we do have a snippet to help you achieve this goal. Simply add the following snippet to your theme’s (or child theme’s) functions.php file, and users will be able to add your events to their personal calendar directly from their ticket email.

<?php
//* Do NOT include the opening php tag

add_action( 'tribe_tickets_ticket_email_ticket_bottom', 'add_export_buttons_to_email' );

function add_export_buttons_to_email( array $ticket ) {
	if ( ! class_exists( 'Tribe__Events__Main' ) ) {
		return;
	}

	global $post;
	$post = get_post( $ticket['event_id'] );

	if ( empty( $post ) ) {
		return;
	}

	$ical_link = add_query_arg( 'ical', '1', get_the_permalink( $post->ID ) );
	
	// Use the following line if you want to have `webcal://` links, that are wiped by Gmail and others.
	// $ical_link = str_replace( [ 'http://', 'https://' ], 'webcal://', $ical_link );

	$calendar_links = '<div class="tribe-events-cal-links">';
	$calendar_links .= '<a class="tribe-events-gcal tribe-events-button" href="' . Tribe__Events__Main::instance()->esc_gcal_url( tribe_get_gcal_link() ) . '" target="_blank" rel="noopener noreferrer" title="' . esc_attr__( 'Add to Google Calendar', 'the-events-calendar' ) . '">+ ' . esc_html__( 'Google Calendar', 'the-events-calendar' ) . '</a>';
	$calendar_links .= '   ';
	$calendar_links .= '<a class="tribe-events-ical tribe-events-button" href="' . esc_url( $ical_link ) . '" title="' . esc_attr__( 'Download .ics file', 'the-events-calendar' ) . '" >+ ' . esc_html__( 'Add to iCalendar', 'the-events-calendar' ) . '</a>';
	$calendar_links .= '</div><!-- .tribe-events-cal-links -->';

	echo $calendar_links;
}