Tribe__Tickets__Tickets_Handler::get_ticket_totals( int|WP_Post $ticket )
Gets the Total of Stock, Sold and Pending for a given ticket
Contents
Parameters
- $ticket
-
(int|WP_Post) (Required) Which ticket
Return
(array)
Source
File: src/Tribe/Tickets_Handler.php
public function get_ticket_totals( $ticket ) {
if ( ! $ticket instanceof WP_Post ) {
$ticket = get_post( $ticket );
}
if ( ! $ticket instanceof WP_Post ) {
return false;
}
$provider = tribe_tickets_get_ticket_provider( $ticket->ID );
$totals = array(
'stock' => get_post_meta( $ticket->ID, '_stock', true ),
'sold' => 0,
'pending' => 0,
);
if ( $provider instanceof Tribe__Tickets_Plus__Commerce__EDD__Main ) {
$totals['sold'] = $provider->stock()->get_purchased_inventory( $ticket->ID, array( 'publish' ) );
$totals['pending'] = $provider->stock()->count_incomplete_order_items( $ticket->ID );
} elseif ( $provider instanceof Tribe__Tickets_Plus__Commerce__WooCommerce__Main ) {
$totals['sold'] = get_post_meta( $ticket->ID, 'total_sales', true );
$totals['pending'] = $provider->get_qty_pending( $ticket->ID, true );
} else {
$totals['sold'] = get_post_meta( $ticket->ID, 'total_sales', true );
}
$totals = array_map( 'intval', $totals );
// Remove Pending from total
$totals['sold'] -= $totals['pending'];
return $totals;
}
Changelog
| Version | Description |
|---|---|
| 4.6 | Introduced. |