Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active March 20, 2024 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/1e0d8ec292695da637664ab91a5d5fed to your computer and use it in GitHub Desktop.
Save andrasguseo/1e0d8ec292695da637664ab91a5d5fed to your computer and use it in GitHub Desktop.
ET > Custom additional fields for RSVPs and tickets, and adding them to the email - for the new ticket emails
<?php
/**
* Add additional fields for Tickets (extension needed!) and add that information to the
* ticket email.
*
* Requirements:
* - Event Tickets
* - New ticket emails - https://theeventscalendar.com/knowledgebase/event-tickets-emails/
* - Event Tickets Additional Fields extension - https://theeventscalendar.com/extensions/additional-fields-for-tickets/
* - Sample code included below. Customize based on your needs.
* - Template override, see additional file
*
* Usage:
* - Add the snippet to your functions.php file or with a plugin like Code Snippets.
* - Add the tickets.php file to wp-content/themes/[your-theme]/tribe/tickets/emails/template-parts/body/tickets.php
*
* @author Andras Guseo
*
* Plugins required: Event Tickets, Event Tickets Additional Fields extension
* Created: March 6, 2024
* Last updated: March 7, 2024
*/
/**
* Add custom fields to tickets.
* @link https://theeventscalendar.com/extensions/additional-fields-for-tickets/
*/
function custom_tickets_additional_fields( $ticket_fields ) {
$ticket_fields['zoom_link'] = [
'type' => 'url',
'label' => esc_html__( 'Zoom link' ),
'description' => esc_html__( 'Insert the Zoom link.' ),
];
$ticket_fields['youtube_embed'] = [
'type' => 'textarea',
'label' => esc_html__( 'YouTube embed' ),
'description' => esc_html__( 'Embed code of recorded webinar.' ),
];
return $ticket_fields;
}
add_filter( 'tribe_ext_tickets_additional_fields', 'custom_tickets_additional_fields' );
<?php
/**
* Event Tickets Emails: Main template > Body > Tickets.
*
* This is a template override for the following file:
* wp-content/plugins/event-tickets/src/views/emails/template-parts/body/tickets.php
*
* This file should be placed at:
* wp-content/themes/[your-theme]/tribe/tickets/emails/template-parts/body/tickets.php
*
* See more documentation about our views templating system.
*
* @link https://evnt.is/tickets-emails-tpl Help article for Tickets Emails template files.
* If you are looking for Event related templates, see in The Events Calendar plugin.
*
* @version 5.5.9
*
* @since 5.5.9
*
* @var Tribe__Template $this Current template object.
* @var \TEC\Tickets\Emails\Email_Abstract $email The email object.
* @var bool $preview Whether the email is in preview mode or not.
* @var bool $is_tec_active Whether `The Events Calendar` is active or not.
* @var array $tickets The list of tickets.
* @var WP_Post|null $event The event post object with properties added by the `tribe_get_event` function.
*
* @see tribe_get_event() For the format of the event object.
*/
if ( empty( $tickets ) ) {
return;
}
$i = 0;
$this->template( 'template-parts/body/tickets-total' );
?>
<tr>
<td style="padding:0;">
<table class="tec-tickets__email-table-content-tickets" role="presentation">
<?php foreach ( $tickets as $ticket ) : ?>
<?php $i++; ?>
<tr>
<td class="tec-tickets__email-table-content-ticket">
<table class="tec-tickets__email-table-content-ticket-table">
<tr>
<?php $this->template( 'template-parts/body/ticket/holder-name', [ 'ticket' => $ticket ] ); ?>
<?php $this->template( 'template-parts/body/ticket/ticket-name', [ 'ticket' => $ticket ] ); ?>
</tr>
<tr>
<?php $this->template( 'template-parts/body/ticket/security-code', [ 'ticket' => $ticket ] ); ?>
</tr>
</table>
<?php $this->template( 'template-parts/body/ticket/number-from-total', [ 'i' => $i ] ); ?>
</td>
</tr>
<!-- START: TICKET CUSTOM FIELDS -->
<?php if ( function_exists( 'tribe_ext_tickets_additional_fields_get_meta' ) ) : ?>
<tr>
<td>
<h6 style="margin:0 0 4px 0; text-transform:uppercase; font-size:14px;"><?php esc_html_e( 'Zoom Link' ); ?></h6>
<a href="<?php echo esc_url( tribe_ext_tickets_additional_fields_get_meta( $ticket['product_id'], 'zoom_link' ) ); ?>"><?php echo esc_html( tribe_ext_tickets_additional_fields_get_meta( $ticket['product_id'], 'zoom_link' ) ); ?></a>
</td>
</tr>
<tr>
<td>
<h6 style="margin:0 0 4px 0; text-transform:uppercase; font-size:14px;"><?php esc_html_e( 'YouTube Embed' ); ?></h6>
<?php echo esc_html( tribe_ext_tickets_additional_fields_get_meta( $ticket['product_id'], 'youtube_embed' ) ); ?>
</td>
</tr>
<?php endif; ?>
<!-- END: TICKET CUSTOM FIELDS -->
<?php endforeach; ?>
</table>
</td>
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment