Tribe__Tickets__Commerce__PayPal__Main::commerce_get_tickets_in_cart( array $tickets )
Get all tickets currently in the cart for Commerce.
Contents
Parameters
- $tickets
-
(array) (Required) List of tickets.
Return
(array) List of tickets.
Source
File: src/Tribe/Commerce/PayPal/Main.php
public function commerce_get_tickets_in_cart( $tickets ) {
/** @var Tribe__Tickets__Commerce__PayPal__Gateway $gateway */
$gateway = tribe( 'tickets.commerce.paypal.gateway' );
$invoice_number = $gateway->get_invoice_number( false );
if ( empty( $invoice_number ) ) {
return $tickets;
}
/** @var Tribe__Tickets__Commerce__PayPal__Cart__Interface $cart */
$cart = tribe( 'tickets.commerce.paypal.cart' );
$cart->set_id( $invoice_number );
$contents = $cart->get_items();
if ( empty( $contents ) ) {
return $tickets;
}
$event_key = $this->event_key;
$optout_key = $this->attendee_optout_key;
foreach ( $contents as $ticket_id => $item ) {
$optout = false;
if ( is_array( $item ) ) {
$ticket_quantity = $item['quantity'];
if ( isset( $item[ $this->attendee_optout_key ] ) ) {
$optout = $item[ $this->attendee_optout_key ];
}
} else {
$ticket_quantity = $item;
}
$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' => 'tribe-commerce',
];
}
return $tickets;
}
Changelog
| Version | Description |
|---|---|
| 4.11.0 | Introduced. |