Automattic\WooCommerce\Checkout\Helpers

ReserveStock::remember_order_for_shopper │ private │ WC 1.0

Records a stock-holding order against the current customer session.

The session's customer id is stamped alongside the ids so the list can be discarded if it later turns up in somebody else's session. See get_session_stock_holding_order_ids().

Method of the class: ReserveStock{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->remember_order_for_shopper( $order ): void;
$order(WC_Order) (required)
Order that now holds stock.

ReserveStock::remember_order_for_shopper() code WC 11.3.0

private function remember_order_for_shopper( \WC_Order $order ): void {
	$session = WC()->session;

	// An order created in the admin or over WP-CLI has no session to record against.
	if ( ! $session instanceof \WC_Session ) {
		return;
	}

	$order_ids = $this->get_session_stock_holding_order_ids( $session );

	array_unshift( $order_ids, $order->get_id() );

	$order_ids = array_slice( array_values( array_unique( array_map( 'absint', $order_ids ) ) ), 0, self::MAX_OWN_ORDERS );

	$session->set(
		self::OWN_ORDERS_SESSION_KEY,
		array(
			'customer'  => (string) $session->get_customer_id(),
			'order_ids' => $order_ids,
		)
	);
}