Tribe__Tickets__Commerce__PayPal__Main::attendee_decreases_inventory( array $attendee )
Whether a specific attendee is valid toward inventory decrease or not.
Contents
By default only attendees generated as part of a Completed order will count toward an inventory decrease but, if the option to reserve stock for Pending Orders is activated, then those attendees generated as part of a Pending Order will, for a limited time after the order creation, cause the inventory to be decreased.
Parameters
- $attendee
-
(array) (Required)
Return
(bool)
Source
File: src/Tribe/Commerce/PayPal/Main.php
public function attendee_decreases_inventory( array $attendee ) {
$order_status = Tribe__Utils__Array::get( $attendee, 'order_status', 'undefined' );
$order_id = Tribe__Utils__Array::get( $attendee, 'order_id', false );
/**
* Whether the pending Order stock reserve logic should be ignored completely or not.
*
* If set to `true` then the behaviour chosen in the Settings will apply, if `false`
* only Completed tickets will count to decrease the inventory. This is useful when
*
* @since 4.7
*
* @param bool $ignore_pending
* @param array $attendee An array of data defining the current Attendee
*/
$ignore_pending = apply_filters( 'tribe_tickets_tpp_pending_stock_ignore', $this->ignore_pending_stock_logic );
if (
'on-pending' === tribe_get_option( 'ticket-paypal-stock-handling', 'on-complete' )
&& ! $ignore_pending
&& Tribe__Tickets__Commerce__PayPal__Stati::$pending === $order_status
&& false !== $order_id
&& false !== $order = Tribe__Tickets__Commerce__PayPal__Order::from_attendee_id( $order_id )
) {
/** @var \Tribe__Tickets__Commerce__PayPal__Order $order */
$order_creation_timestamp = Tribe__Date_Utils::wp_strtotime( $order->get_creation_date() );
/**
* Filters the amount of time a part of the stock will be reserved by a pending Order.
*
* The time applies from the Order creation time.
* In the unlikely scenario that an Order goes from Completed to Pending then, if the
* reservation time allows it, a part of the stock will be reserved for it.
*
* @since 4.7
*
* @param int $pending_stock_reservation_time The amount of seconds, from the Order creation time,
* part of the stock will be reserved for the Order;
* defaults to 30 minutes.
* @param array $attendee An array of data defining the current Attendee
* @param Tribe__Tickets__Commerce__PayPal__Order $order The object representing the Order that generated
* the Attendee
*/
$pending_stock_reservation_time = (int) apply_filters( 'tribe_tickets_tpp_pending_stock_reserve_time', 30 * 60, $attendee, $order );
return current_time( 'timestamp' ) <= ( $order_creation_timestamp + $pending_stock_reservation_time );
}
return Tribe__Tickets__Commerce__PayPal__Stati::$completed === $order_status;
}
Changelog
| Version | Description |
|---|---|
| 4.7 | Introduced. |