MEC_USER_BOOKING_COMPLETED::mec_booking_completed( $booking_id )

Callback function to register trigger parameters.


Parameters Parameters

$booking_id

(Required) The accepted post id of mec_user_booking_cancelled action.


Top ↑

Return Return

(Uncanny_Automatorvoid.)


Source Source

File: src/integrations/modern-events-calendar/triggers/mec-user-booking-completed.php

	public function mec_booking_completed( $booking_id ) {



		$matched_recipe_ids = array();

		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );

		$event = Automator()->get->meta_from_recipes( $recipes, $this->trigger_code );

		$event_id = absint( get_post_meta( $booking_id, 'mec_event_id', true ) );

		$attendees = get_post_meta( $booking_id, 'mec_attendees', true );

		foreach ( $recipes as $recipe_id => $recipe ) {

			foreach ( $recipe['triggers'] as $trigger ) {

				$trigger_id = $trigger['ID'];

				// Check to see if trigger matches `Any` trigger or a specific Event.
				if (
					intval( '-1' ) === intval( $event[ $recipe_id ][ $trigger_id ] )
					|| intval( $event_id ) === intval( $event[ $recipe_id ][ $trigger_id ] )
				) {

					$matched_recipe_ids[] = array(
						'recipe_id'  => $recipe_id,
						'trigger_id' => $trigger_id,
					);

				}
			}
		}

			// Run each trigger for each registered users.
		foreach ( $attendees as $key => $attendee ) {

			$user = get_user_by( 'email', $attendee['email'] );

			if ( ! empty( $user ) && ! empty( $user->ID ) ) {

				if ( ! empty( $matched_recipe_ids ) ) {

					foreach ( $matched_recipe_ids as $matched_recipe_id ) {

						$args = array(
							'code'             => $this->trigger_code,
							'meta'             => $this->trigger_meta,
							'user_id'          => $user->ID,
							'recipe_to_match'  => $matched_recipe_id['recipe_id'],
							'trigger_to_match' => $matched_recipe_id['trigger_id'],
							'ignore_post_id'   => true,
						);

						$args = Automator()->maybe_add_trigger_entry( $args, false );

						// Save trigger meta
						if ( $args ) {

							foreach ( $args as $result ) {

								if ( true === $result['result'] && $result['args']['trigger_id'] && $result['args']['get_trigger_id'] ) {

									$run_number = Automator()->get->trigger_run_number( $result['args']['trigger_id'], $result['args']['get_trigger_id'], $user->ID );

									$event_book_id_action_meta = array(
										'user_id'        => $user->ID,
										'trigger_id'     => $result['args']['trigger_id'],
										'run_number'     => $run_number, //get run number
										'trigger_log_id' => $result['args']['get_trigger_id'],
										'meta_key'       => $this->trigger_meta,
										'meta_value'     => sprintf( 'EVENT_BOOKING_%d_COMPLETED', $booking_id ),
									);

									Automator()->insert_trigger_meta( $event_book_id_action_meta );

									// Save the Event Id as trigger meta.
									$event_id_action_meta = array(
										'user_id'        => $user->ID,
										'trigger_id'     => $result['args']['trigger_id'],
										'run_number'     => $run_number, //get run number
										'trigger_log_id' => $result['args']['get_trigger_id'],
										'meta_key'       => 'MEC_EVENT_ID',
										'meta_value'     => sprintf( '%d', $event_id ),
									);

									Automator()->insert_trigger_meta( $event_id_action_meta );

									Automator()->maybe_trigger_complete( $result['args'] );

								}
							}
						}
					}
				}
			}
		}

	}