Tribe__Tickets__Commerce__PayPal__Main::send_tickets_email( string $order_id, int $post_id = null )

Sends ticket email


Parameters

$order_id

(string) (Required) Order post ID

$post_id

(int) (Optional) Parent post ID (optional)

Default value: null


Top ↑

Source

File: src/Tribe/Commerce/PayPal/Main.php

	public function send_tickets_email( $order_id, $post_id = null ) {
		$all_attendees = $this->get_attendees_by_order_id( $order_id );

		$to_send = array();

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

		// Look at each attendee and check if a ticket was sent: in each case where a ticket
		// has not yet been sent we should a) send the ticket out by email and b) record the
		// fact it was sent
		foreach ( $all_attendees as $single_attendee ) {
			// Only add those attendees/tickets that haven't already been sent
			if ( ! empty( $single_attendee[ 'ticket_sent' ] ) ) {
				continue;
			}

			$to_send[] = $single_attendee;
			update_post_meta( $single_attendee[ 'qr_ticket_id' ], $this->attendee_ticket_sent, true );
		}

		/**
		 * Controls the list of tickets which will be emailed out.
		 *
		 * @since 4.7
		 * @since 4.7.6 added new parameter $post_id
		 *
		 * @param array $to_send        list of tickets to be sent out by email
		 * @param array $all_attendees  list of all attendees/tickets, including those already sent out
		 * @param int   $post_id
		 * @param int   $order_id
		 *
		 */
		$to_send = (array) apply_filters( 'tribe_tickets_tpp_tickets_to_send', $to_send, $all_attendees, $post_id, $order_id );

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

		// For now all ticket holders in an order share the same email
		$to = $all_attendees['0']['holder_email'];

		if ( ! is_email( $to ) ) {
			return;
		}

		/**
		 * Filters the Tribe Commerce tickets email content
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param string  email content
		 * @param int     $post_id
		 * @param int     $order_id
		 */
		$content = apply_filters( 'tribe_tpp_email_content', $this->generate_tickets_email_content( $to_send ), $post_id, $order_id );

		/**
		 * Filters the Tribe Commerce tickets email sender name
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param string  email sender name
		 * @param int     $post_id
		 * @param int     $order_id
		 */
		$from = apply_filters( 'tribe_tpp_email_from_name', tribe_get_option( 'ticket-paypal-confirmation-email-sender-name', false ), $post_id, $order_id );

		/**
		 * Filters the Tribe Commerce tickets email sender email
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param string  email sender email
		 * @param int     $post_id
		 * @param int     $order_id
		 */
		$from_email = apply_filters( 'tribe_tpp_email_from_email', tribe_get_option( 'ticket-paypal-confirmation-email-sender-email', false ), $post_id, $order_id );

		$headers = array( 'Content-type: text/html' );

		if ( ! empty( $from ) && ! empty( $from_email ) ) {
			$headers[] = sprintf( 'From: %s <%s>', filter_var( $from, FILTER_SANITIZE_STRING ), filter_var( $from_email, FILTER_SANITIZE_EMAIL ) );
		}

		/**
		 * Filters the Tribe Commerce tickets email headers
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param array  email headers
		 * @param int    $post_id
		 * @param int    $order_id
		 */
		$headers = apply_filters( 'tribe_tpp_email_headers', $headers, $post_id, $order_id );

		/**
		 * Filters the Tribe Commerce tickets email attachments
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param array  attachments
		 * @param int    $post_id
		 * @param int    $order_id
		 */
		$attachments = apply_filters( 'tribe_tpp_email_attachments', array(), $post_id, $order_id );

		/**
		 * Filters the Tribe Commerce tickets email recipient
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param string  $to
		 * @param int     $event_id
		 * @param int     $order_id
		 */
		$to = apply_filters( 'tribe_tpp_email_recipient', $to, $post_id, $order_id );

		$site_name = stripslashes_deep( html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
		$default_subject = sprintf( __( 'Your tickets from %s', 'event-tickets' ), $site_name );

		/**
		 * Filters the Tribe Commerce tickets email subject
		 *
		 * @since 4.7.6 added new parameters $post_id and $order_id
		 *
		 * @param string  email subject
		 * @param int     $post_id
		 * @param int     $order_id
		 */
		$subject = apply_filters( 'tribe_tpp_email_subject', tribe_get_option( 'ticket-paypal-confirmation-email-subject', $default_subject ) );

		wp_mail( $to, $subject, $content, $headers, $attachments );
	}

Top ↑

Changelog

Changelog
Version Description
4.7.6 Introduced.