Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::get_orders_type()
Fetch order type for orders in bulk.
Method of the class: OrdersTableDataStore{}
No Hooks.
Returns
Array
. array( $order_id1 => $type1, ... ) Array for all orders.
Usage
$OrdersTableDataStore = new OrdersTableDataStore(); $OrdersTableDataStore->get_orders_type( $order_ids );
- $order_ids(array) (required)
- Order IDs.
OrdersTableDataStore::get_orders_type() OrdersTableDataStore::get orders type code WC 9.8.5
public function get_orders_type( $order_ids ) { global $wpdb; if ( empty( $order_ids ) ) { return array(); } $order_types = array(); if ( OrderUtil::custom_orders_table_datastore_cache_enabled() ) { if ( ! is_array( $order_ids ) ) { // self::get_order_data_for_ids() strict types the $order_ids parameter. Temporarily maintain backward compatibility // for potential misuse of self::get_orders_type(). $order_ids = array( (int) $order_ids ); } // If we're using order data caching, preemptively pull all the data and prime the cache as this method is // almost exclusively used to determine the order class to later hydrate. $orders_data = $this->get_order_data_for_ids( $order_ids ); foreach ( $orders_data as $order_id => $order_data ) { if ( ! empty( $order_data->type ) ) { $order_types[ $order_id ] = $order_data->type; } } return $order_types; } $orders_table = self::get_orders_table_name(); $order_ids_placeholder = implode( ', ', array_fill( 0, count( $order_ids ), '%d' ) ); // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $results = $wpdb->get_results( $wpdb->prepare( "SELECT id, type FROM {$orders_table} WHERE id IN ( $order_ids_placeholder )", $order_ids ) ); // phpcs:enable foreach ( $results as $row ) { $order_types[ $row->id ] = $row->type; } return $order_types; }