Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active April 10, 2022 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/fc7f1687b26c7292672ead9f26c4d568 to your computer and use it in GitHub Desktop.
Save cliffordp/fc7f1687b26c7292672ead9f26c4d568 to your computer and use it in GitHub Desktop.
Event Tickets & Plus: Attach a file from Media Library to all ticket emails.
<?php
/**
* Event Tickets & Plus: Attach a file from Media Library to all ticket emails.
*
* Does not work for emails for declined RSVPs or for moved tickets, but it
* could if you want it to; just add those additional hooks.
*
* @link https://gist.github.com/cliffordp/fc7f1687b26c7292672ead9f26c4d568
* @link https://theeventscalendar.com/support/forums/topic/pdf-attachment-file-to-ticket-email/
*/
function cliff_attach_file_to_all_tickets( array $attachments ) {
// !!! CHANGE THIS !!!
$attachment_id = 6391;
// We do it this way to make sure we get the path, not the link.
$file = get_attached_file( $attachment_id );
if ( file_exists( $file ) ) {
$attachments[] = $file;
}
return $attachments;
}
add_action( 'tribe_rsvp_email_attachments', 'cliff_attach_file_to_all_tickets', 50 );
add_action( 'tribe_tpp_email_attachments', 'cliff_attach_file_to_all_tickets', 50 );
add_action( 'tribe_tickets_plus_woo_email_attachments', 'cliff_attach_file_to_all_tickets', 50 );
add_action( 'edd_ticket_receipt_attachments', 'cliff_attach_file_to_all_tickets', 50 );
@mariomelchor
Copy link

mariomelchor commented Apr 12, 2018

This is great for adding attachments to all ticket emails. Is it possible to add attachments for a specific event only?

@fabricelaborie
Copy link

I'm also looking for a solution to attach event-specific document !

@cliffordp
Copy link
Author

@mariomelchor & @fabricelaborie - I'm sure you could create a custom field to pick a media item (or just get the featured image, for example) for each event (or use Events Calendar Pro's custom fields) and incorporate that into this snippet somehow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment