Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::get_orders_type()publicWC 1.0

Fetch order type for orders in bulk.

Метод класса: OrdersTableDataStore{}

Хуков нет.

Возвращает

Массив. array( $order_id1 => $type1, ... ) Array for all orders.

Использование

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->get_orders_type( $order_ids );
$order_ids(массив) (обязательный)
Order IDs.

Код OrdersTableDataStore::get_orders_type() WC 9.3.3

public function get_orders_type( $order_ids ) {
	global $wpdb;

	if ( empty( $order_ids ) ) {
		return array();
	}

	$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
	$order_types = array();
	foreach ( $results as $row ) {
		$order_types[ $row->id ] = $row->type;
	}
	return $order_types;
}