Tribe__Tickets_Plus__Commerce__WooCommerce__Main::order_has_tickets( int $order_id )
Checks if a Order has Tickets
Contents
Parameters
- $order_id
-
(int) (Required)
Return
(boolean)
Source
File: src/Tribe/Commerce/WooCommerce/Main.php
public function order_has_tickets( $order_id ) {
$has_tickets = false;
$done = get_post_meta( $order_id, $this->order_has_tickets, true );
/**
* get_post_meta returns empty string when the meta doesn't exists
* in support 2 possible values:
* - Empty string which will do the logic using WC_Order below
* - Cast boolean the return of the get_post_meta
*/
if ( '' !== $done ) {
return (bool) $done;
}
// Get the items purchased in this order
$order = new WC_Order( $order_id );
$order_items = $order->get_items();
// Bail if the order is empty
if ( empty( $order_items ) ) {
return $has_tickets;
}
// Iterate over each product
foreach ( (array) $order_items as $item_id => $item ) {
$product_id = isset( $item['product_id'] ) ? $item['product_id'] : $item['id'];
// Get the event this tickets is for
$post_id = get_post_meta( $product_id, $this->event_key, true );
if ( ! empty( $post_id ) ) {
$has_tickets = true;
break;
}
}
return $has_tickets;
}