<?php
/**
* The Events Calendar (TEC) and Event Aggregator (EA): Link Site B's imported TEC events to their canonical Event
* Tickets location on Site A. Displays a big button on Site B's single events pages.
*
* Useful when you want to import and display Site A's events (running TEC and ET/ET+) on Site B (running TEC and EA).
* WARNING: Watch out if you're also importing from other sources, like Google, Eventbrite, etc.
* Read this snippet's code comments to make sure you understand what this code does and what it does not do.
*
* @link https://gist.github.com/cliffordp/aab5ea85e9bd409d09cb8e22a3690a25 This snippet.
* @link https://cl.ly/43705ea2b5d6 GIF of this snippet in action on Site B.
* @link https://theeventscalendar.com/knowledgebase/creating-hub-site-event-aggregator/ Link Site B's events (running EA) to Site A's tickets.
* @link https://cl.ly/6b07851ee7c7 Example import settings (for single event).
* @link https://cl.ly/f22b7c37a0a7 View of Site B's database entry from Site A's imported event data.
*/
function tribe_tec_ea_hub_site_b_link_back_to_site_a_tickets() {
$site_a_event_link = get_post_meta( get_the_ID(), Tribe__Events__Aggregator__Event::$source_key, true );
// Might also want to check if this event doesn't have its own tickets.
if (
// Bail if no import source.
empty( $site_a_event_link )
// Bail if no cost was imported, which will be set on Site B if Site A event had a ticket.
// Remove this logic if Site A adds its first ticket AFTER Site B already imported it... or manually set an Event Cost for Site B's event data.
|| empty( tribe_get_cost() )
) {
return;
}
/**
* We just assume every Site A is a TEC site and that it has tickets.
* Might want to customize to add additional sanity checks to avoid bad linking...
* such as whitelisting the domain(s) of sites we import from...
* such as SiteA.com and SiteZ.com so we don't link to Eventbrite.com
*
* Hash:
* #buy-tickets If Site A uses Event Tickets Plus (ET+) - WooCommerce or Easy Digital Downloads.
* #rsvp-now If Site A uses RSVP.
* #tpp-buy-tickets If Site A uses Tribe PayPal Tickets.
*
* If Site A uses more than one of these ticket types, just drop the hash or leave it there (will work the same).
* Example URL: https://wpshindig.com/event/event-tickets-demo/#rsvp-now
*/
printf(
'<div class="%s" style="text-align: center;">
<a href="%s" target="_blank">
<button class="tribe-button" style="padding: 40px; font-size: 200%%;">
Check Ticket Availability
</button>
</a>
<br>
<small><em>
(Link opens in a new window.)
</em></small>
</div>',
__FUNCTION__,
trailingslashit( $site_a_event_link ) . '#rsvp-now'
);
}
/**
* Top of event, after featured image.
*/
add_action( 'tribe_events_single_event_before_the_content', 'tribe_tec_ea_hub_site_b_link_back_to_site_a_tickets' );
/**
* Bottom of event, after meta box(es).
* FYI: Event Tickets hook into tribe_events_single_event_after_the_meta at Priority 4.
* Relevant if Site B events might add their own tickets in addition.
*/
add_action( 'tribe_events_single_event_after_the_meta', 'tribe_tec_ea_hub_site_b_link_back_to_site_a_tickets' );