Tribe__Tickets_Plus__Commerce__WooCommerce__Main::count_order_items_by_status( int $ticket_id, string $status = 'incomplete' )
Determine the total number of the specified ticket contained in orders which have progressed to a “completed” or “incomplete” status.
Contents
Essentially this returns the total quantity of tickets held within orders that are complete or incomplete (incomplete are: "pending", "on hold" or "processing").
Parameters
- $ticket_id
-
(int) (Required)
- $status
-
(string) (Optional) Types of orders: incomplete or complete
Default value: 'incomplete'
Return
(int)
Source
File: src/Tribe/Commerce/WooCommerce/Main.php
public function count_order_items_by_status( $ticket_id, $status = 'incomplete' ) {
$totals = array(
'total' => 0,
'recorded_sales' => 0,
'reduced_stock' => 0,
);
$incomplete_orders = version_compare( '2.5', WooCommerce::instance()->version, '<=' ) ?
$this->get_orders_by_status( $ticket_id, $status ) : $this->backcompat_get_orders_by_status( $ticket_id, $status );
foreach ( $incomplete_orders as $order_id ) {
$order = new WC_Order( $order_id );
$has_recorded_sales = 'yes' === get_post_meta( $order_id, '_recorded_sales', true );
$has_reduced_stock = (bool) get_post_meta( $order_id, '_order_stock_reduced', true );
foreach ( (array) $order->get_items() as $order_item ) {
if ( $order_item['product_id'] == $ticket_id ) {
$totals['total'] += (int) $order_item['qty'];
if ( $has_recorded_sales ) {
$totals['recorded_sales'] += (int) $order_item['qty'];
}
if ( $has_reduced_stock ) {
$totals['reduced_stock'] += (int) $order_item['qty'];
}
}
}
}
return $totals;
}