Tribe__Tickets_Plus__Commerce__EDD__Cart::commerce_get_tickets_in_cart( array $tickets = array() )

Get all tickets currently in the cart for Commerce.


Parameters

$tickets

(array) (Optional) List of tickets.

Default value: array()


Top ↑

Return

(array) List of tickets.


Top ↑

Source

File: src/Tribe/Commerce/EDD/Cart.php

	public function commerce_get_tickets_in_cart( $tickets = [] ) {
		$contents = edd_get_cart_contents();

		if ( empty( $contents ) ) {
			return $tickets;
		}

		/** @var \Tribe__Tickets_Plus__Commerce__EDD__Main $commerce_edd */
		$commerce_edd = tribe( 'tickets-plus.commerce.edd' );

		$event_key  = $commerce_edd->event_key;
		$optout_key = $commerce_edd->attendee_optout_key;

		foreach ( $contents as $item ) {
			$ticket_id       = $item['id'];
			$ticket_quantity = $item['quantity'];
			$optout          = false;

			if ( isset( $item['options'][ $optout_key ] ) ) {
				$optout = $item['options'][ $optout_key ];
			}

			$post_id = (int) get_post_meta( $ticket_id, $event_key, true );

			if ( empty( $post_id ) ) {
				continue;
			}

			$optout = filter_var( $optout, FILTER_VALIDATE_BOOLEAN );
			$optout = $optout ? 'yes' : 'no';

			$tickets[] = [
				'ticket_id' => $ticket_id,
				'quantity'  => $ticket_quantity,
				'post_id'   => $post_id,
				'optout'    => $optout,
				'provider'  => 'edd',
			];
		}

		/**
		 * Allows for filtering the returned tickets for easier third-party plugin compatibility.
		 *
		 * @since 4.10.8
		 *
		 * @param array $tickets  List of tickets currently in the cart.
		 * @param array $contents The EDD cart contents.
		 */
		return apply_filters( 'tribe_tickets_plus_edd_tickets_in_cart', $tickets, $contents );
	}

Top ↑

Changelog

Changelog
Version Description
4.11.0 Introduced.