AMELIABOOKING_TOKENS::save_token_data( mixed $args, mixed $trigger )

Save the token data.


Parameters Parameters

$args

(Required)

$trigger

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/ameliabooking/tokens/ameliabooking-tokens.php

	public function save_token_data( $args, $trigger ) {

		if ( ! isset( $args['trigger_args'] ) || ! isset( $args['entry_args']['code'] ) ) {
			return;
		}

		// Check if trigger code is for Amelia.
		if ( in_array( $args['entry_args']['code'], self::APPOINTMENT_BOOKING_TOKENS_TRIGGERS, true ) ) {

			$booking_data_arr = array_shift( $args['trigger_args'] );

			// Add the category name.
			$booking_data_arr['category']['name'] = $this->fetch_category_name( absint( $booking_data_arr['appointment']['serviceId'] ) );

			// Add the service name.
			$booking_data_arr['service']['name'] = $this->fetch_service_name( absint( $booking_data_arr['appointment']['serviceId'] ) );

			// Add the customer WordPress user id.
			$booking_data_arr['customer']['wpUserId'] = 0;

			if ( isset( $booking_data_arr['customer']['email'] ) && ! empty( $booking_data_arr['customer']['email'] ) ) {

				$wp_user = get_user_by( 'email', $booking_data_arr['customer']['email'] );

				if ( false !== $wp_user ) {
					$booking_data_arr['customer']['wpUserId'] = $wp_user->ID;
				}
			}

			$booking_data = wp_json_encode( $booking_data_arr );

			Automator()->db->token->save( 'AMELIA_BOOKING_DATA', $booking_data, $args['trigger_entry'] );

		}

	}