Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active September 1, 2020 18:15
Show Gist options
  • Save cliffordp/35d3c0a08e53b061920976f80f0f44b4 to your computer and use it in GitHub Desktop.
Save cliffordp/35d3c0a08e53b061920976f80f0f44b4 to your computer and use it in GitHub Desktop.
MT - ET - ET+ - Change email From Address and From Name only when sending ticket emails -- works for RSVP and WooCommerce
<?php
/**
* MT - ET - ET+ - Change email From Address and From Name only when sending ticket emails -- works for RSVP, WooCommerce, and Easy Digital Downloads
*
* From https://gist.github.com/cliffordp/35d3c0a08e53b061920976f80f0f44b4
*
* For https://theeventscalendar.com/support/forums/topic/change-the-sender-email-address-for-all-events-ticket-related-emails/
*/
// RSVP
add_action( 'event_tickets_rsvp_tickets_generated', 'cliff_et_custom_from_email' );
// WooCommerce
add_action( 'event_tickets_woocommerce_tickets_generated', 'cliff_et_custom_from_email' );
// EDD
add_action( 'event_tickets_edd_ticket_created', 'cliff_et_custom_from_email' );
// call the other functions via filters
function cliff_et_custom_from_email() {
// RSVP
add_filter( 'wp_mail_from', 'cliff_custom_tickets_email_from' );
add_filter( 'wp_mail_from_name', 'cliff_custom_tickets_email_from_name' );
// WooCommerce
add_filter( 'woocommerce_email_from_address', 'cliff_custom_tickets_email_from' );
add_filter( 'woocommerce_email_from_name', 'cliff_custom_tickets_email_from_name' );
// EDD
add_filter( 'edd_email_from_address', 'cliff_custom_tickets_email_from' );
add_filter( 'edd_email_from_name', 'cliff_custom_tickets_email_from_name' );
}
// set the Email From Address
function cliff_custom_tickets_email_from() {
// From Address
$address = 'tickets@example.com'; // manually enter this
$address = sanitize_email( $address );
return $address;
}
// set the Email From Name
function cliff_custom_tickets_email_from_name() {
// From Name based on site settings, or manually enter this too
$name = sprintf( 'Tickets from %s', get_option( 'blogname' ) ); // e.g. Tickets from Cliff's Event Site
$name = esc_html( $name );
return $name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment