Tribe__Tickets__Attendee_Registration__View::display_attendee_registration_shortcode()

Render the Attendee Info shortcode.


Return

(string) The resulting template content


Top ↑

Source

File: src/Tribe/Attendee_Registration/View.php

	public function display_attendee_registration_shortcode() {
		$q_provider = tribe_get_request_var( 'provider', false );

		/**
		 * Filter to add/remove tickets from the global cart
		 *
		 * @since 4.9
		 * @since 4.11.0 Added $q_provider to allow context of current provider.
		 *
		 * @param array  $tickets_in_cart The array containing the cart elements. Format array( 'ticket_id' => 'quantity' ).
		 * @param string $q_provider      Current ticket provider.
		 */
		$tickets_in_cart = apply_filters( 'tribe_tickets_tickets_in_cart', [], $q_provider );

		$events           = [];
		$providers        = [];
		$default_provider = [];

		foreach ( $tickets_in_cart as $ticket_id => $quantity ) {
			// Load the tickets in cart for each event, with their ID, quantity and provider.
			$ticket = tribe( 'tickets.handler' )->get_object_connections( $ticket_id );

			// If we've got a provider and it doesn't match, skip the ticket
			if ( empty( $ticket->provider ) ) {
				continue;
			}

			$ticket_providers = [
				$ticket->provider->attendee_object,
			];

			if ( ! empty( $ticket->provider->orm_provider ) ) {
				$ticket_providers[] = $ticket->provider->orm_provider;
			}

			// If we've got a provider and it doesn't match, skip the ticket
			if ( ! in_array( $q_provider, $ticket_providers, true ) ) {
				continue;
			}

			$ticket_data = [
				'id'       => $ticket_id,
				'qty'      => $quantity,
				'provider' => $ticket->provider,
			];

			/**
			 * Flag for event form to flag TPP. This is used for the AJAX
			 * feature for save attendee information. If the provider is
			 * TPP, then AJAX saving is disabled.
			 *
			 * @todo: This is temporary until we can figure out what to do
			 *        with the Attendee Registration page handling multiple
			 *        payment providers.
			 */
			$provider = '';

			if ( empty( $default_provider ) ) {
				// One provider per instance.
				$default_provider[ $q_provider ] = $ticket->provider->class_name;
			}

			switch ( $ticket->provider->class_name ) {
				case 'Tribe__Tickets__Commerce__PayPal__Main':
					$provider = 'tpp';
					break;
				case 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main':
					$provider = 'woo';
					break;
				case 'Tribe__Tickets_Plus__Commerce__EDD__Main':
					$provider = 'edd';
					break;
				default:
					break;
			}

			$providers[ $ticket->event ] = $provider;
			$events[ $ticket->event ][]  = $ticket_data;
		}

		/**
		 * Check if the cart has a ticket with required meta fields
		 *
		 * @since TDB
		 *
		 * @param boolean $cart_has_required_meta Whether the cart has required meta.
		 * @param array   $tickets_in_cart        The array containing the cart elements. Format array( 'ticket_id' => 'quantity' ).
		 */
		$cart_has_required_meta = (bool) apply_filters( 'tribe_tickets_attendee_registration_has_required_meta', ! empty( $tickets_in_cart ), $tickets_in_cart );

		// Get the checkout URL, it'll be added to the checkout button
		$checkout_url = tribe( 'tickets.attendee_registration' )->get_checkout_url();

		/**
		 * Filter to check if there's any required meta that wasn't filled in
		 *
		 * @since TDB
		 *
		 * @param bool
		 */
		$is_meta_up_to_date = (int) apply_filters( 'tribe_tickets_attendee_registration_is_meta_up_to_date', true );

		/**
		 *  Set all the template variables
		 */
		$args = [
			'events'                 => $events,
			'checkout_url'           => $checkout_url,
			'is_meta_up_to_date'     => $is_meta_up_to_date,
			'cart_has_required_meta' => $cart_has_required_meta,
			'providers'              => $providers,
		];

		// Enqueue styles and scripts specific to this page.
		tribe_asset_enqueue( 'event-tickets-registration-page-styles' );
		tribe_asset_enqueue( 'event-tickets-registration-page-scripts' );

		// One provder per instance
		$currency  = tribe( 'tickets.commerce.currency' )->get_currency_config_for_provider( $default_provider, null );
		wp_localize_script(
			'event-tickets-registration-page-scripts',
			'TribeCurrency',
			[
				'formatting' => json_encode( $currency )
			]
		);
		wp_localize_script(
			'event-tickets-registration-page-scripts',
			'TribeCartEndpoint',
			[
				'url' => tribe_tickets_rest_url( '/cart/' )
			]
		);


		wp_enqueue_style( 'dashicons' );

		$this->add_template_globals( $args );

		return $this->template( 'registration-js/content', $args, false );
	}

Top ↑

Changelog

Changelog
Version Description
4.12.3 Get provider slug more consistently.
4.12.0 Introduced.