WooCommerce Code Reference

WC_Cart_Session
in package

WC_Cart_Session class.

Tags
since
3.2.0

Table of Contents

$cart  : WC_Cart
Reference to cart object.
__construct()  : mixed
Sets up the items provided, and calculate totals.
destroy_cart_session()  : mixed
Destroy cart session data.
get_cart_for_session()  : array
Returns the contents of the cart in an array without the 'data' element.
get_cart_from_session()  : mixed
Get the cart data from the PHP session and store it in class variables.
init()  : mixed
Register methods for this object on the appropriate WordPress hooks.
maybe_set_cart_cookies()  : mixed
Will set cart cookies if needed and when possible.
persistent_cart_destroy()  : mixed
Delete the persistent cart permanently.
persistent_cart_update()  : mixed
Save the persistent cart when the cart is updated.
set_session()  : mixed
Sets the php session data for the cart and coupons.
get_saved_cart()  : array
Get the persistent cart from the database.
populate_cart_from_order()  : array
Get a cart from an order, if user has permission.
set_cart_cookies()  : mixed
Set cart hash cookie and items in cart if not already set.

Properties

Methods

__construct()

Sets up the items provided, and calculate totals.

public __construct(WC_Cart &$cart) : mixed
Parameters
$cart : WC_Cart

Cart object to calculate totals for.

Tags
since
3.2.0
throws
Exception

If missing WC_Cart object.

Return values
mixed

get_cart_for_session()

Returns the contents of the cart in an array without the 'data' element.

public get_cart_for_session() : array
Return values
arraycontents of the cart

get_cart_from_session()

Get the cart data from the PHP session and store it in class variables.

public get_cart_from_session() : mixed
Tags
since
3.2.0
Return values
mixed

maybe_set_cart_cookies()

Will set cart cookies if needed and when possible.

public maybe_set_cart_cookies() : mixed
Tags
since
3.2.0
Return values
mixed

persistent_cart_update()

Save the persistent cart when the cart is updated.

public persistent_cart_update() : mixed
Return values
mixed

get_saved_cart()

Get the persistent cart from the database.

private get_saved_cart() : array
Tags
since
3.5.0
Return values
array

populate_cart_from_order()

Get a cart from an order, if user has permission.

private populate_cart_from_order(int $order_id, array $cart) : array
Parameters
$order_id : int

Order ID to try to load.

$cart : array

Current cart array.

Tags
since
3.5.0
Return values
array

set_cart_cookies()

Set cart hash cookie and items in cart if not already set.

private set_cart_cookies([bool $set = true ]) : mixed
Parameters
$set : bool = true

Should cookies be set (true) or unset.

Return values
mixed