WC_Abstract_Order::get_persisted_item_ids │ private │ WC 1.0

Get IDs of items currently persisted for this order.

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

Хуков нет.

Возвращает

array<int>.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_persisted_item_ids( $type ): array;
$type(строка|null)
Item type, or null for every registered item type.
По умолчанию: null

Код WC_Abstract_Order::get_persisted_item_ids() WC 11.3.0

private function get_persisted_item_ids( $type = null ): array {
	/**
	 * Data store wrapper.
	 *
	 * @var WC_Data_Store $data_store
	 */
	$data_store = $this->data_store;

	if ( $data_store->has_callable( 'get_item_ids' ) ) {
		// @phpstan-ignore-next-line -- Optional data store method checked above.
		$item_ids = $data_store->get_item_ids( $this, $type );

		return array_values(
			array_unique(
				array_filter(
					array_map( 'intval', (array) $item_ids ),
					static fn( $item_id ) => $item_id > 0
				)
			)
		);
	}

	$types = null === $type
		? array_keys( $this->get_item_types_to_group() )
		: array( $type );

	$item_ids = array();
	foreach ( $types as $item_type ) {
		if ( ! is_string( $item_type ) || '' === $item_type ) {
			continue;
		}

		// @phpstan-ignore-next-line -- Required order data store method forwarded by WC_Data_Store::__call().
		$items = $this->data_store->read_items( $this, $item_type );
		foreach ( (array) $items as $item ) {
			if ( ! $item instanceof WC_Order_Item ) {
				continue;
			}
			$item_id = absint( $item->get_id() );

			if ( $item_id && $this->get_id() === (int) $item->get_order_id() ) {
				$item_ids[] = $item_id;
			}
		}
	}

	return array_values( array_unique( $item_ids ) );
}