Tribe__Tickets__Tickets::exclude_past_tickets_from_cost_range( array $costs, int $post_id, string $meta, bool $single )

Filter past tickets from showing up in cost range.


Parameters

$costs

(array) (Required) List of ticket costs.

$post_id

(int) (Required) Target Event's ID.

$meta

(string) (Required) Meta key name.

$single

(bool) (Required) determines if the requested meta should be a single item or an array of items.


Top ↑

Return

(array) The list of ticket costs with past tickets excluded possibly.


Top ↑

Source

File: src/Tribe/Tickets.php

		public function exclude_past_tickets_from_cost_range( $costs, $post_id, $meta, $single ) {

			if ( '_EventCost' != $meta || $single || empty( $costs )  ) {
				return $costs;
			}

			/**
			 * Allow filtering of whether to exclude past tickets in the event cost range.
			 *
			 * @since 5.1.4
			 *
			 * @param bool  $exclude_past_tickets Whether to exclude past tickets in the event cost range.
			 * @param array $costs                Which costs are going to be displayed.
			 * @param int   $post_id              Which Event/Post we are dealign with.
			 */
			$exclude_past_tickets = apply_filters( 'event_tickets_exclude_past_tickets_from_cost_range', false, $costs, $post_id );

			if ( ! $exclude_past_tickets ) {
				return $costs;
			}

			$tickets = self::get_all_event_tickets( $post_id );

			$wp_timezone = Tribe__Timezones::wp_timezone_string();

			if ( Tribe__Timezones::is_utc_offset( $wp_timezone ) ) {
				$wp_timezone = Tribe__Timezones::generate_timezone_string_from_utc_offset( $wp_timezone );
			}

			$timezone = new DateTimeZone( $wp_timezone );

			foreach ( $tickets as $ticket ) {

				$now        = Tribe__Date_Utils::build_date_object( 'now', $timezone );
				$start_date = Tribe__Date_Utils::build_date_object( $ticket->start_date . ' ' . $ticket->start_time, $timezone );
				$end_date   = Tribe__Date_Utils::build_date_object( $ticket->end_date . ' ' . $ticket->end_time, $timezone );

				// If the ticket has not yet become available for sale or has already ended.
				if ( $now < $start_date || $end_date < $now ) {
					// Try to find the ticket price in the list of costs.
					$key = array_search( $ticket->price, $costs );

					// Remove the value from the list of costs if we found it.
					if ( false !== $key ) {
						unset( $costs[ $key ] );
					}
					continue;
				}
			}

			return $costs;
		}

Top ↑

Changelog

Changelog
Version Description
5.1.5 Introduced.