Tribe__Tickets__RSVP::update_attendee_data( array $attendee_data, int $attendee_id, int $post_id )

Update the RSVP values for this user.

Note that, within this method, $attendee_id refers to the attendee or ticket ID (it does not refer to an "order" in the sense of a transaction that may include multiple tickets, as is the case in some other methods for instance).


Parameters

$attendee_data

(array) (Required) Information that we are trying to save.

$attendee_id

(int) (Required) The attendee ID.

$post_id

(int) (Required) The event/post ID.


Top ↑

Source

File: src/Tribe/RSVP.php

	public function update_attendee_data( $data, $order_id, $event_id ) {
		$user_id = get_current_user_id();

		$rsvp_orders    = $this->tickets_view->get_event_rsvp_attendees( $event_id, $user_id );
		$rsvp_order_ids = array_map( 'absint', wp_list_pluck( $rsvp_orders, 'order_id' ) );

		// This makes sure we don't save attendees for orders that are not from this current user and event
		if ( ! in_array( (int) $order_id, $rsvp_order_ids, true ) ) {
			return;
		}

		$attendee = array();

		// Get the Attendee Data, it's important for testing
		foreach ( $rsvp_orders as $test_attendee ) {
			if ( $order_id !== $test_attendee['order_id'] ) {
				continue;
			}

			$attendee = $test_attendee;
		}

		// Dont try to Save if it's restricted
		if ( ! isset( $attendee['product_id'] )
		     || $this->tickets_view->is_rsvp_restricted( $event_id, $attendee['product_id'] )
		) {
			return;
		}

		$attendee_email     = empty( $data['email'] ) ? null : sanitize_email( $data['email'] );
		$attendee_email     = is_email( $attendee_email ) ? $attendee_email : null;
		$attendee_full_name = empty( $data['full_name'] ) ? null : sanitize_text_field( $data['full_name'] );
		$attendee_optout    = empty( $data['optout'] ) ? false : (bool) $data['optout'];

		if ( empty( $data['order_status'] ) || ! $this->tickets_view->is_valid_rsvp_option( $data['order_status'] ) ) {
			$attendee_order_status = null;
		} else {
			$attendee_order_status = $data['order_status'];
		}

		$product_id  = $attendee['product_id'];

		//check if changing status will cause rsvp to go over capacity
		$previous_order_status = get_post_meta( $order_id, self::ATTENDEE_RSVP_KEY, true );

		// The status changed from "not going" to "going", check if we have the capacity to support it.
		if ( tribe_is_truthy( $attendee_order_status ) && in_array( $previous_order_status, $this->get_statuses_by_action( 'count_not_going' ), true ) ) {
			$capacity = tribe_tickets_get_capacity( $product_id );
			$sales = (int) get_post_meta( $product_id, 'total_sales', true );
			$unlimited = -1;
			if ( $unlimited !== $capacity && $sales + 1 > $capacity ) {
				return;
			}
		}

		$this->update_sales_and_stock_by_order_status( $order_id, $attendee_order_status, $product_id );

		if ( null !== $attendee_order_status ) {
			update_post_meta( $order_id, self::ATTENDEE_RSVP_KEY, $attendee_order_status );
		}

		update_post_meta( $order_id, self::ATTENDEE_OPTOUT_KEY, (bool) $attendee_optout );

		if ( null !== $attendee_full_name ) {
			update_post_meta( $order_id, $this->full_name, $attendee_full_name );
		}

		if ( null !== $attendee_email ) {
			update_post_meta( $order_id, $this->email, $attendee_email );
		}
	}