WC_Order_Factory::get_orders()public staticWC 1.0

Get multiple orders (by ID).

{} Это метод класса: WC_Order_Factory{}

Хуков нет.

Возвращает

Массив[\WC_Order].

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

$result = WC_Order_Factory::get_orders( $order_ids, $skip_invalid );
$order_ids(array[mixed])
Array of order IDs to get.
По умолчанию: array()
$skip_invalid(true|false)
(default: false) TRUE if invalid IDs or orders should be ignored.
По умолчанию: false

Код WC_Order_Factory::get_orders() WC 6.9.4

public static function get_orders( $order_ids = array(), $skip_invalid = false ) {
	$result    = array();
	$order_ids = array_filter( array_map( array( __CLASS__, 'get_order_id' ), $order_ids ) );

	foreach ( $order_ids as $order_id ) {
		$classname = self::get_class_name_for_order_id( $order_id );

		if ( ! $classname && ! $skip_invalid ) {
			// translators: %d is an order ID.
			throw new \Exception( sprintf( __( 'Could not find classname for order ID %d', 'woocommerce' ), $order_id ) );
		}

		try {
			$obj = new $classname();
			$obj->set_defaults();
			$obj->set_id( $order_id );

			$result[ $order_id ] = $obj;
		} catch ( \Exception $e ) {
			wc_caught_exception( $e, __FUNCTION__, array( $order_id ) );

			if ( ! $skip_invalid ) {
				throw $e;
			}
		}
	}

	try {
		WC_Data_Store::load( 'order' )->read_multiple( $result );
	} catch ( \Exception $e ) {
		wc_caught_exception( $e, __FUNCTION__, $order_ids );

		if ( ! $skip_invalid ) {
			throw $e;
		}
	}

	return $result;
}