Automattic\WooCommerce\StoreApi\Routes\V1\Agentic
AgenticCheckoutSession::get_or_set_checkout_session_id
Get the checkout session ID. If it does not exist, generate a cart token for it and save to the current session.
Method of the class: AgenticCheckoutSession{}
No Hooks.
Returns
String. Checkout Session ID stored in the current session.
Usage
// private - for code of main (parent) class only $result = $this->get_or_set_checkout_session_id(): string;
AgenticCheckoutSession::get_or_set_checkout_session_id() AgenticCheckoutSession::get or set checkout session id code WC 10.7.0
private function get_or_set_checkout_session_id(): string {
$wc_session = WC()->session;
if ( null === $wc_session ) {
return '';
}
$session_id = $wc_session->get( SessionKey::AGENTIC_CHECKOUT_SESSION_ID );
if ( null === $session_id ) {
$session_id = CartTokenUtils::get_cart_token( (string) $wc_session->get_customer_id() );
$wc_session->set( SessionKey::AGENTIC_CHECKOUT_SESSION_ID, $session_id );
}
return $session_id;
}