Ec_Tokens::ec_possible_tokens( array $tokens = array(), array $args = array() )

Prepare tokens.


Parameters Parameters

$tokens

(Optional) .

Default value: array()

$args

(Optional) .

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/integrations/event-tickets/tokens/ec-tokens.php

	public function ec_possible_tokens( $tokens = array(), $args = array() ) {
		if ( ! automator_do_identify_tokens() ) {
			return $tokens;
		}

		$event_id     = $args['value'];
		$trigger_meta = $args['meta'];

		if ( empty( $event_id ) || intval( '-1' ) === intval( $event_id ) ) {
			return $tokens;
		}

		if ( ! class_exists( '\Tribe__Tickets__Tickets' ) ) {
			return $tokens;
		}

		if ( ! method_exists( '\Tribe__Tickets__Tickets', 'get_all_event_tickets' ) ) {
			return $tokens;
		}

		$tickets = \Tribe__Tickets__Tickets::get_all_event_tickets( $event_id );

		if ( ! class_exists( '\Tribe__Tickets_Plus__Meta' ) ) {
			return $tokens;
		}

		if ( ! method_exists( '\Tribe__Tickets_Plus__Meta', 'get_attendee_meta_fields' ) ) {
			return $tokens;
		}

		if ( empty( $tickets ) ) {
			return $tokens;
		}

		$new_tokens = array();
		foreach ( $tickets as $ticket ) {
			$new_tokens = array(
				array(
					'tokenId'         => sprintf( '%s|tribe-tickets-plus-iac-name', sanitize_title( $ticket->name ) ),
					'tokenName'       => sprintf( '%s — Name', $ticket->name ),
					'tokenType'       => 'text',
					'tokenIdentifier' => $trigger_meta,
				),
				array(
					'tokenId'         => sprintf( '%s|tribe-tickets-plus-iac-email', sanitize_title( $ticket->name ) ),
					'tokenName'       => sprintf( '%s — Email', $ticket->name ),
					'tokenType'       => 'email',
					'tokenIdentifier' => $trigger_meta,
				),
			);

			$meta = \Tribe__Tickets_Plus__Meta::get_attendee_meta_fields( $ticket->ID );
			if ( empty( $meta ) ) {
				continue;
			}
			foreach ( $meta as $fields ) {
				switch ( $fields['type'] ) {
					case 'email':
						$type = 'email';
						break;
					case 'number':
						$type = 'int';
						break;
					default:
						$type = 'text';
						break;
				}

				$new_tokens[] = array(
					'tokenId'         => sprintf( '%s|%s', sanitize_title( $ticket->name ), $fields['slug'] ),
					'tokenName'       => sprintf( '%s — %s', $ticket->name, $fields['label'] ),
					'tokenType'       => $type,
					'tokenIdentifier' => $trigger_meta,
				);
			}
		}

		return array_merge( $tokens, $new_tokens );
	}