Tribe__Tickets__Attendee_Repository::set_attendee_args( array $attendee_data, Tribe__Tickets__Ticket_Object $ticket = null )

Set arguments for attendee.


Parameters

$ticket

(Tribe__Tickets__Ticket_Object) (Optional) The ticket object or null if not relying on it.

Default value: null

$attendee_data

(array) (Required) List of additional attendee data.


Top ↑

Source

File: src/Tribe/Attendee_Repository.php

	public function set_attendee_args( $attendee_data, $ticket = null ) {
		$args = [
			'attendee_id'       => null,
			'title'             => null,
			'full_name'         => null,
			'email'             => null,
			'ticket_id'         => $ticket ? $ticket->ID : null,
			'post_id'           => $ticket ? $ticket->get_event_id() : null,
			'order_id'          => null,
			'order_attendee_id' => null,
			'user_id'           => null,
			'attendee_status'   => null,
			'price_paid'        => null,
			'optout'            => null,
		];

		$args = array_merge( $args, $attendee_data );

		$attendee_id = null;

		$ignored = [
			'send_ticket_email',
			'send_ticket_email_args',
		];

		// Remove ignored arguments from being saved.
		foreach ( $ignored as $ignore ) {
			if ( isset( $args[ $ignore ] ) ) {
				unset( $args[ $ignore ] );
			}
		}

		// Unset the attendee ID if found.
		if ( isset( $args['attendee_id'] ) ) {
			$attendee_id = $args['attendee_id'];

			unset( $args['attendee_id'] );
		}

		// Do some extra set up if creating an attendee.
		if ( null === $attendee_id ) {
			// Default attendees to opted-out.
			if ( null === $args['optout'] ) {
				$args['optout'] = 1;
			}

			// Attempt to create order if none set.
			if ( empty( $args['order_id'] ) && $ticket ) {
				$order_id = $this->create_order_for_attendee( $args, $ticket );

				if ( $order_id ) {
					$args['order_id'] = $order_id;
				}
			}

			// If the title is empty, set the title from the full name.
			if ( empty( $args['title'] ) && $args['full_name'] ) {
				$args['title'] = $args['full_name'];

				// Maybe add the Order ID.
				if ( $args['order_id'] ) {
					$args['title'] = $args['order_id'] . ' | ' . $args['title'];
				}

				// Maybe add the Order Attendee ID.
				if ( null !== $args['order_attendee_id'] ) {
					$args['title'] .= ' | ' . $args['order_attendee_id'];
				}
			}

			// Maybe handle setting the User ID based on information we already have.
			if ( empty( $args['user_id'] ) && ! empty( $args['email'] ) && $this->attendee_provider ) {
				$user_id = $this->attendee_provider->maybe_setup_attendee_user_from_email( $args['email'], $args );

				if ( $user_id ) {
					$args['user_id'] = $user_id;
				}
			}

			if ( isset( $args['optout'] ) ) {
				// Enforce a 0/1 value for the optout value.
				$args['optout'] = (int) tribe_is_truthy( $args['optout'] );
			}
		}

		// Handle any customizations per provider for the attendee arguments.
		$args = $this->setup_attendee_args( $args, $attendee_data, $ticket );

		/**
		 * Allow filtering the arguments to set for the attendee.
		 *
		 * @since 5.1.0
		 *
		 * @param array                         $args          List of arguments to set for the attendee.
		 * @param array                         $attendee_data List of additional attendee data.
		 * @param Tribe__Tickets__Ticket_Object $ticket        The ticket object or null if not relying on it.
		 */
		$args = apply_filters( 'tribe_tickets_attendee_repository_set_attendee_args', $args, $attendee_data, $ticket );

		// Maybe run filter if using a provider key name.
		if ( $this->key_name ) {
			/**
			 * Allow filtering the arguments to set for the attendee by provider key name.
			 *
			 * @since 5.1.0
			 *
			 * @param array                         $args          List of arguments to set for the attendee.
			 * @param array                         $attendee_data List of additional attendee data.
			 * @param Tribe__Tickets__Ticket_Object $ticket        The ticket object or null if not relying on it.
			 */
			$args = apply_filters( 'tribe_tickets_attendee_repository_set_attendee_args_' . $this->key_name, $args, $attendee_data, $ticket );
		}

		// Remove arguments that are null.
		$args = array_filter(
			$args,
			static function ( $value ) {
				return ! is_null( $value );
			}
		);

		// Remove unused arguments from saving.
		if ( isset( $args['order_attendee_id'] ) ) {
			unset( $args['order_attendee_id'] );
		}

		$this->set_args( $args );
	}

Top ↑

Changelog

Changelog
Version Description
5.1.0 Introduced.