WooCommerce Code Reference

CartTokenUtils
in package

Cart token utility functions.

Table of Contents

get_cart_token()  : string
Generate a cart token.
get_cart_token_expiration()  : int
Gets the expiration of the cart token. Defaults to 48h.
get_cart_token_payload()  : array<string|int, mixed>
Get the cart token payload.
get_request_cart_token()  : string
Get the cart token sent with the current HTTP request.
validate_cart_token()  : bool
Validate the cart token.
get_cart_token_secret()  : string
Get the cart token secret.

Methods

get_cart_token()

Generate a cart token.

public static get_cart_token(string $customer_id) : string
Parameters
$customer_id : string

The customer ID.

Return values
string

get_cart_token_expiration()

Gets the expiration of the cart token. Defaults to 48h.

public static get_cart_token_expiration() : int
Tags
since
11.1.0

Made public.

Return values
int

get_cart_token_payload()

Get the cart token payload.

public static get_cart_token_payload(string $cart_token) : array<string|int, mixed>

Returns an empty payload unless the signature validates.

Parameters
$cart_token : string

The cart token.

Tags
since
11.1.0

Returns an empty payload for tokens that fail signature validation.

Return values
array<string|int, mixed>

get_request_cart_token()

Get the cart token sent with the current HTTP request.

public static get_request_cart_token() : string
Tags
since
11.1.0
Return values
string

validate_cart_token()

Validate the cart token.

public static validate_cart_token(string $cart_token) : bool
Parameters
$cart_token : string

The cart token.

Return values
bool