Automattic\WooCommerce\Checkout\Helpers
ReserveStock::get_session_stock_holding_order_ids
Returns the stock-holding order ids recorded against the current session.
The list is only trusted if it was written under this session's customer id.
Method of the class: ReserveStock{}
No Hooks.
Returns
int[].
Usage
// private - for code of main (parent) class only $result = $this->get_session_stock_holding_order_ids( $session ): array;
- $session(WC_Session) (required)
- Session of the shopper making this request.
ReserveStock::get_session_stock_holding_order_ids() ReserveStock::get session stock holding order ids code WC 11.3.0
private function get_session_stock_holding_order_ids( \WC_Session $session ): array {
$remembered = $session->get( self::OWN_ORDERS_SESSION_KEY, array() );
if ( ! is_array( $remembered ) ) {
return array();
}
if ( ! isset( $remembered['customer'], $remembered['order_ids'] ) || ! is_array( $remembered['order_ids'] ) ) {
return array();
}
// Core hands session data to a different shopper in two places (cart token
// cloning and guest-to-user migration), and both change the session
// customer id first. A mismatch means the list arrived from somebody
// else's session, so it confers no ownership.
if ( (string) $remembered['customer'] !== (string) $session->get_customer_id() ) {
return array();
}
return array_slice( array_map( 'absint', $remembered['order_ids'] ), 0, self::MAX_OWN_ORDERS );
}