Automattic\WooCommerce\Checkout\Helpers

ReserveStock::get_potential_stock_holding_order_ids_for_customer │ private │ WC 1.0

Returns order ids of a signed-in customer that could be holding stock, newest first.

Covers a shopper whose session pointers were lost (new device, cleared cookies, lapsed session). The statuses match the ones the reserved stock query counts.

Method of the class: ReserveStock{}

No Hooks.

Returns

int[].

Usage

// private - for code of main (parent) class only
$result = $this->get_potential_stock_holding_order_ids_for_customer( $customer_id ): array;
$customer_id(int) (required)
Customer ID.

ReserveStock::get_potential_stock_holding_order_ids_for_customer() code WC 11.3.0

private function get_potential_stock_holding_order_ids_for_customer( int $customer_id ): array {
	if ( isset( self::$potential_order_ids_by_customer[ $customer_id ] ) ) {
		return self::$potential_order_ids_by_customer[ $customer_id ];
	}

	/** @var int[] $order_ids */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
	$order_ids = wc_get_orders(
		array(
			'customer' => $customer_id,
			'status'   => array( OrderStatus::CHECKOUT_DRAFT, OrderStatus::PENDING ),
			'limit'    => self::MAX_OWN_ORDERS,
			'orderby'  => 'date',
			'order'    => 'DESC',
			'return'   => 'ids',
		)
	);

	$order_ids = array_map( 'absint', $order_ids );

	self::$potential_order_ids_by_customer[ $customer_id ] = $order_ids;

	return $order_ids;
}