Tribe__Events__Community__Tickets__Fees::calculate_ticket_fee( array $tickets, Tribe__Events__Community__Tickets__Gateway__Abstract|null $gateway = null, int $event_id )

Calculate fees per ticket.


Parameters

$tickets

(array) (Required) List of tickets.

$gateway

(Tribe__Events__Community__Tickets__Gateway__Abstract|null) (Optional) Gateway object.

Default value: null

$event_id

(int) (Required) An optional Event ID.


Top ↑

Return

(float) Fee that will be added to ticket.


Top ↑

Source

File: src/Tribe/Fees.php

	public function calculate_ticket_fee( array $tickets, $gateway = null, $event_id = 0 ) {
		if ( null === $gateway ) {
			/** @var Tribe__Events__Community__Tickets__Main $main */
			$main     = tribe( 'community-tickets.main' );
			$gateway  = $main->gateway( 'PayPal' );
		}

		$flat_on_free = $gateway->site_fee_on_free();
		$fee          = 0;

		foreach ( $tickets as $ticket ) {
			$ticket_quantity = isset( $ticket['quantity'] ) ? (int) $ticket['quantity'] : 1;

			// If there is an event ID specified, only return fees for that event.
			if ( ! empty( $event_id ) && $event_id !== $ticket['event_id'] ) {
				continue;
			}

			$ticket_price = 0;

			if ( isset( $ticket['ticket-price'] ) ) {
				$ticket_price = (float) $ticket['ticket-price'];
			} elseif ( isset( $ticket['price'] ) ) {
				$ticket_price = (float) $ticket['price'];
			}

			// If the ticket is free and "Add flat fees to free tickets" is disabled, skip free tickets.
			if ( ! $flat_on_free && $ticket_price <= 0 ) {
				continue;
			}

			$ticket_fee = $this->get_ticket_fee_from_price( $ticket_price, $ticket['payment_fee_setting'] );

			// Prevent fee from being more than the price if using 'absorb' payment fee setting.
			if ( 'absorb' === $ticket['payment_fee_setting'] ) {
				$ticket_fee = min( $ticket_price, $ticket_fee );
			}

			$fee += $ticket_quantity * $ticket_fee;
		}

		return $fee;
	}

Top ↑

Changelog

Changelog
Version Description
4.7.1 - Added an optional event id to return total fee for an event and not the order.
4.6.2 Introduced.