Ticket::is_on_sale( Tribe__Tickets__Ticket_Object $ticket )

Check if a ticket is on sale.


Parameters

$ticket

(Tribe__Tickets__Ticket_Object) (Required) The ticket object.


Top ↑

Return

(bool) Whether the ticket is on sale.


Top ↑

Source

File: src/Tickets/Commerce/Ticket.php

	public function is_on_sale( Ticket_Object $ticket ): bool {
		$sale_checked = get_post_meta( $ticket->ID, static::$sale_price_checked_key, true );

		if ( ! $sale_checked ) {
			return false;
		}

		$sale_price = get_post_meta( $ticket->ID, static::$sale_price_key, true );

		if ( empty( $sale_price ) ) {
			return false;
		}

		$start_date = get_post_meta( $ticket->ID, static::$sale_price_start_date_key, true );
		$end_date   = get_post_meta( $ticket->ID, static::$sale_price_end_date_key, true );

		if ( empty( $start_date ) && empty( $end_date ) ) {
			return true;
		}

		// Using the ticket's date helper to ensure the timezone for events are handled correctly.
		$start = $ticket->get_date( $start_date );
		$end   = $ticket->get_date( $end_date );
		$now   = $ticket->get_date( 'today' );

		// If the sale has no end date and the start date is in the past, the sale is on.
		if ( $start <= $now && empty( $end ) ) {
			return true;
		}

		return $now >= $start && $now <= $end;
	}

Top ↑

Changelog

Changelog
Version Description
5.9.0 Introduced.