Automattic\WooCommerce\StoreApi

Authentication::maybe_use_store_api_session_handlerpublicWC 10.6.0

Use the Store API session handler when a valid Cart-Token is present.

Method of the class: Authentication{}

No Hooks.

Returns

String.

Usage

$Authentication = new Authentication();
$Authentication->maybe_use_store_api_session_handler( $handler ): string;
$handler(string) (required)
Session handler class name.

Changelog

Since 10.6.0 Introduced.

Authentication::maybe_use_store_api_session_handler() code WC 10.8.1

public function maybe_use_store_api_session_handler( $handler ): string {
	if ( ! WC()->is_store_api_request() && ! $this->has_store_api_route_as_get_parameter() ) {
		return $handler;
	}

	$cart_token = wc_clean( wp_unslash( $_SERVER['HTTP_CART_TOKEN'] ?? '' ) );
	$cart_token = is_string( $cart_token ) ? $cart_token : '';
	if ( $cart_token && CartTokenUtils::validate_cart_token( $cart_token ) ) {
		return SessionHandler::class;
	}
	return $handler;
}