Tribe__Tickets__Commerce__PayPal__Main::add_ticket_to_cart( int $ticket_id, int $quantity, array $extra_data = array(), boolean $additive = true )

Handles the process of adding a ticket product to the cart.

If the cart contains a line item for the product, this will replace the previous quantity. If the quantity is zero and the cart contains a line item for the product, this will remove it.


Parameters

$ticket_id

(int) (Required) Ticket ID.

$quantity

(int) (Required) Ticket quantity.

$extra_data

(array) (Optional) Extra data to send to the cart item.

Default value: array()

$additive

(boolean) (Optional) Whether to add or replace tickets.

Default value: true


Top ↑

Source

File: src/Tribe/Commerce/PayPal/Main.php

	public function add_ticket_to_cart( $ticket_id, $quantity, array $extra_data = [], $additive = true ) {
		if ( empty( $extra_data['cart'] ) ) {
			return;
		}

		$optout_key = $this->attendee_optout_key;

		/** @var Tribe__Tickets__Commerce__PayPal__Cart__Unmanaged $cart */
		$cart = $extra_data['cart'];

		if ( ! $additive ) {
			// Remove from the cart so we can replace it below (add_item is additive).
			$cart->remove_item( $ticket_id );
		}

		if ( 0 < $quantity ) {
			$optout = isset( $extra_data[ $optout_key ] ) ? $extra_data[ $optout_key ] : false;
			$optout = filter_var( $optout, FILTER_VALIDATE_BOOLEAN );
			$optout = $optout ? 'yes' : 'no';

			$extra_item_data = [
				$this->attendee_optout_key => $optout,
			];

			// Add to / update quantity in cart.
			$cart->add_item( $ticket_id, $quantity, $extra_item_data );
		}
	}

Top ↑

Changelog

Changelog
Version Description
4.11.0 Introduced.