Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::get_order_data_for_ids()privateWC 1.0

Return order data for multiple IDs.

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

No Hooks.

Return

\stdClass[]|Object|null. DB Order objects or error.

Usage

// private - for code of main (parent) class only
$result = $this->get_order_data_for_ids( $ids );
$ids(array) (required)
List of order IDs.

Код OrdersTableDataStore::get_order_data_for_ids() WC 7.1.0

private function get_order_data_for_ids( $ids ) {
	if ( ! $ids ) {
		return array();
	}

	global $wpdb;
	if ( empty( $ids ) ) {
		return array();
	}
	$order_table_query = $this->get_order_table_select_statement();
	$id_placeholder    = implode( ', ', array_fill( 0, count( $ids ), '%d' ) );
	$order_meta_table  = self::get_meta_table_name();

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $order_table_query is autogenerated and should already be prepared.
	$table_data = $wpdb->get_results(
		$wpdb->prepare(
			"$order_table_query WHERE wc_order.id in ( $id_placeholder )",
			$ids
		)
	);
	// phpcs:enable

	$meta_data_query = $this->get_order_meta_select_statement();
	$order_data      = array();
	$meta_data       = $wpdb->get_results(
		$wpdb->prepare(
			// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $meta_data_query and $order_meta_table is autogenerated and should already be prepared. $id_placeholder is already prepared.
			"$meta_data_query WHERE $order_meta_table.order_id in ( $id_placeholder )",
			$ids
		)
	);
	foreach ( $table_data as $table_datum ) {
		$order_data[ $table_datum->id ]            = $table_datum;
		$order_data[ $table_datum->id ]->meta_data = array();
	}

	foreach ( $meta_data as $meta_datum ) {
		// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Not a meta query.
		$order_data[ $meta_datum->order_id ]->meta_data[] = (object) array(
			'meta_id'    => $meta_datum->id,
			'meta_key'   => $meta_datum->meta_key,
			'meta_value' => $meta_datum->meta_value,
		);
		// phpcs:enable
	}
	return $order_data;
}