WooCommerce Code Reference

WC_Session_Handler extends WC_Session
in package

Session handler class.

Table of Contents

$_cookie  : string
Cookie name used for the session.
$_customer_id  : int
Customer ID.
$_data  : array
Session Data.
$_dirty  : bool
Dirty when the session needs saving.
$_has_cookie  : bool
True when the cookie exists.
$_session_expiration  : string
Stores session due to expire timestamp.
$_session_expiring  : string
Stores session expiry.
$_table  : string
Table name for session data.
__construct()  : mixed
Constructor for the session class.
__get()  : mixed
Magic get method.
__isset()  : bool
Magic isset method.
__set()  : mixed
Magic set method.
__unset()  : mixed
Magic unset method.
cleanup_sessions()  : mixed
Cleanup session data from the database and clear caches.
delete_session()  : mixed
Delete the session from the cache and database.
destroy_session()  : mixed
Destroy all session data.
forget_session()  : mixed
Forget all session data without destroying it.
generate_customer_id()  : string
Generate a unique customer ID for guests, or return user ID if logged in.
get()  : array|string
Get a session variable.
get_customer_id()  : int
Get customer ID.
get_session()  : string|array
Returns the session.
get_session_cookie()  : bool|array
Get the session cookie, if set. Otherwise return false.
get_session_data()  : array
Get session data.
has_session()  : bool
Return true if the current user has an active session, i.e. a cookie to retrieve values.
init()  : mixed
Init hooks and session data.
init_session_cookie()  : mixed
Setup cookie and customer ID.
nonce_user_logged_out()  : string
When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
save_data()  : mixed
Save data and delete guest session.
set()  : mixed
Set a session variable.
set_customer_session_cookie()  : mixed
Sets the session cookie on-demand (usually after adding an item to the cart).
set_session_expiration()  : mixed
Set session expiration.
update_session_timestamp()  : mixed
Update the session expiry timestamp.
use_secure_cookie()  : bool
Should the session cookie be secure?
get_cache_prefix()  : string
Gets a cache prefix. This is used in session names so the entire cache can be invalidated with 1 function call.

Properties

Methods

delete_session()

Delete the session from the cache and database.

public delete_session(int $customer_id) : mixed
Parameters
$customer_id : int

Customer ID.

Return values
mixed

generate_customer_id()

Generate a unique customer ID for guests, or return user ID if logged in.

public generate_customer_id() : string

Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.

Return values
string

get()

Get a session variable.

public get(string $key[, mixed $default = null ]) : array|string
Parameters
$key : string

Key to get.

$default : mixed = null

used if the session variable isn't set.

Return values
array|stringvalue of session variable

get_session()

Returns the session.

public get_session(string $customer_id[, mixed $default = false ]) : string|array
Parameters
$customer_id : string

Custo ID.

$default : mixed = false

Default session value.

Return values
string|array

Get the session cookie, if set. Otherwise return false.

public get_session_cookie() : bool|array

Session cookies without a customer ID are invalid.

Return values
bool|array

has_session()

Return true if the current user has an active session, i.e. a cookie to retrieve values.

public has_session() : bool
Return values
bool

nonce_user_logged_out()

When a user is logged out, ensure they have a unique nonce by using the customer/session ID.

public nonce_user_logged_out(int $uid) : string
Parameters
$uid : int

User ID.

Return values
string

save_data()

Save data and delete guest session.

public save_data(int $old_session_key) : mixed
Parameters
$old_session_key : int

session ID before user logs in.

Return values
mixed

set()

Set a session variable.

public set(string $key, mixed $value) : mixed
Parameters
$key : string

Key to set.

$value : mixed

Value to set.

Return values
mixed

Sets the session cookie on-demand (usually after adding an item to the cart).

public set_customer_session_cookie(bool $set) : mixed

Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.

Warning: Cookies will only be set if this is called before the headers are sent.

Parameters
$set : bool

Should the session cookie be set.

Return values
mixed

update_session_timestamp()

Update the session expiry timestamp.

public update_session_timestamp(string $customer_id, int $timestamp) : mixed
Parameters
$customer_id : string

Customer ID.

$timestamp : int

Timestamp to expire the cookie.

Return values
mixed

get_cache_prefix()

Gets a cache prefix. This is used in session names so the entire cache can be invalidated with 1 function call.

private get_cache_prefix() : string
Return values
string