Hooks::filter_cart_to_checkout_redirect_url( string $redirect_url )

Filters the cart –> checkout redirect URL base.


Parameters #

$redirect_url

(string) (Required) Redirect URL.


Top ↑

Return #

(string)


Top ↑

Source #

File: src/Tickets_Plus/Commerce/Attendee_Registration/Hooks.php

	public function filter_cart_to_checkout_redirect_url( $redirect_url ) {
		if ( tribe( 'tickets.attendee_registration' )->is_modal_enabled() ) {
			return $redirect_url;
		}

		// If we are attempting to redirect to the Checkout page, don't hijack the URL.
		if ( tribe_get_request_var( Checkout::$url_query_arg, false ) ) {
			return $redirect_url;
		}

		/**
		 * All of the logic for IAC and ARF need to moved and consolidated later, as is the amount of logic for this is
		 * insane and very expensive to maintain long term.
		 *
		 * @todo TribeLegacyCommerce
		 */
		$ar_json_string   = stripslashes( Arr::get( $_POST, 'tribe_tickets_ar_data', '' ) );
		$ar_data          = json_decode( $ar_json_string, ARRAY_A );
		$cart_items       = Arr::get( $ar_data, 'tribe_tickets_tickets' );
		$tickets_with_qty = [];
		foreach ( $cart_items as $item ) {
			if ( ! isset( $item['ticket_id'], $item['quantity'] ) ) {
				continue;
			}

			if ( 0 === (int) $item['quantity'] ) {
				continue;
			}

			$tickets_with_qty[] = $item['ticket_id'];
		}

		if ( empty( $tickets_with_qty ) ) {
			return $redirect_url;
		}

		$needs_redirect = false;
		foreach ( $tickets_with_qty as $ticket_id ) {
			if ( IAC::NONE_KEY !== tribe( 'tickets-plus.attendee-registration.iac' )->get_iac_setting_for_ticket( $ticket_id ) ) {
				$needs_redirect = true;
				break;
			}
			$meta = \Tribe__Tickets_Plus__Meta::get_attendee_meta_fields( $ticket_id );

			if ( ! empty( $meta ) ) {
				$needs_redirect = true;
				break;
			}
		}

		if ( ! $needs_redirect ) {
			return $redirect_url;
		}

		$redirect_url = home_url( '/' . tribe( 'tickets.attendee_registration' )->get_slug() );
		$redirect_url = add_query_arg( tribe_tickets_get_provider_query_slug(), \TEC\Tickets\Commerce::PROVIDER, $redirect_url );

		return $redirect_url;
	}

Top ↑

Changelog #

Changelog
Version Description
5.3.0 Introduced.