Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::read_multiple()publicWC 6.9.0

Reads multiple orders from custom tables in one pass.

Method of the class: OrdersTableDataStore{}

No Hooks.

Return

null. Nothing.

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->read_multiple( $orders );
$orders(array[\WC_Order]) (required) (passed by reference — &)
Order objects.

Changelog

Since 6.9.0 Introduced.

OrdersTableDataStore::read_multiple() code WC 7.1.0

public function read_multiple( &$orders ) {
	$order_ids = array_keys( $orders );
	$data      = $this->get_order_data_for_ids( $order_ids );

	if ( count( $data ) !== count( $order_ids ) ) {
		throw new \Exception( __( 'Invalid order IDs in call to read_multiple()', 'woocommerce' ) );
	}

	$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
	if ( ! $data_synchronizer instanceof DataSynchronizer ) {
		return;
	}

	$data_sync_enabled = $data_synchronizer->data_sync_is_enabled() && 0 === $data_synchronizer->get_current_orders_pending_sync_count_cached();
	$load_posts_for    = array_diff( $order_ids, self::$reading_order_ids );
	$post_orders       = $data_sync_enabled ? $this->get_post_orders_for_ids( array_intersect_key( $orders, array_flip( $load_posts_for ) ) ) : array();

	foreach ( $data as $order_data ) {
		$order_id = absint( $order_data->id );
		$order    = $orders[ $order_id ];

		$this->init_order_record( $order, $order_id, $order_data );

		if ( $data_sync_enabled && $this->should_sync_order( $order ) && isset( $post_orders[ $order_id ] ) ) {
			self::$reading_order_ids[] = $order_id;
			$this->maybe_sync_order( $order, $post_orders[ $order->get_id() ] );
		}
	}
}