WooCommerce Code Reference

WC_Legacy_Cart
in package

Legacy cart class.

Table of Contents

$cart_session_data  : mixed
Array of defaults. Not used since 3.2.
$coupon_applied_count  : array
Contains an array of coupon usage counts after they have been applied.
__get()  : mixed
Magic getters.
__isset()  : mixed
Map legacy variables.
__set()  : mixed
Map legacy variables to setters.
add_discount()  : bool
Renamed for consistency.
apply_cart_discounts_after_tax()  : mixed
Function to apply cart discounts after tax.
apply_product_discounts_after_tax()  : mixed
Function to apply product discounts after tax.
coupons_enabled()  : bool
Coupons enabled function. Filterable.
get_cart_discount_tax_total()  : float
Get the total of all cart tax discounts (used for discounts on tax inclusive prices).
get_cart_discount_total()  : float
Get the total of all cart discounts.
get_cart_for_session()  : mixed
get_cart_from_session()  : mixed
Methods moved to session class in 3.2.0.
get_cart_url()  : string
Gets the url to the cart page.
get_checkout_url()  : string
Gets the url to the checkout page.
get_discounted_price()  : float
Function to apply discounts to a product and get the discounted price (before tax is applied).
get_discounts_after_tax()  : mixed
Gets the order discount amount - these are applied after tax.
get_discounts_before_tax()  : mixed
Gets the total (product) discount amount - these are applied before tax.
get_order_discount_total()  : int
Get the total of all order discounts (after tax discounts).
init()  : mixed
Init.
maybe_set_cart_cookies()  : mixed
persistent_cart_destroy()  : mixed
persistent_cart_update()  : mixed
remove_taxes()  : mixed
Remove taxes.
set_session()  : mixed
ship_to_billing_address_only()  : bool
Sees if we need a shipping address.

Properties

$cart_session_data

Array of defaults. Not used since 3.2.

public mixed $cart_session_data = array('cart_contents_total' => 0, 'total' => 0, 'subtotal' => 0, 'subtotal_ex_tax' => 0, 'tax_total' => 0, 'taxes' => array(), 'shipping_taxes' => array(), 'discount_cart' => 0, 'discount_cart_tax' => 0, 'shipping_total' => 0, 'shipping_tax_total' => 0, 'coupon_discount_amounts' => array(), 'coupon_discount_tax_amounts' => array(), 'fee_total' => 0, 'fees' => array())
Tags
deprecated
3.2.0

$coupon_applied_count

Contains an array of coupon usage counts after they have been applied.

public array $coupon_applied_count = array()
Tags
deprecated
3.2.0

Methods

__get()

Magic getters.

public __get(string $name) : mixed

If you add/remove cases here please update $legacy_keys in __isset accordingly.

Parameters
$name : string

Property name.

Return values
mixed

__set()

Map legacy variables to setters.

public __set(string $name, mixed $value) : mixed
Parameters
$name : string

Property name.

$value : mixed

Value to set.

Return values
mixed

add_discount()

Renamed for consistency.

public add_discount(string $coupon_code) : bool
Parameters
$coupon_code : string
Return values
boolTrue if the coupon is applied, false if it does not exist or cannot be applied.

apply_cart_discounts_after_tax()

Function to apply cart discounts after tax.

public apply_cart_discounts_after_tax( $values,  $price) : mixed
Parameters
$values :
$price :
Tags
deprecated
2.3.0

Coupons can not be applied after tax.

Return values
mixed

apply_product_discounts_after_tax()

Function to apply product discounts after tax.

public apply_product_discounts_after_tax( $values,  $price) : mixed
Parameters
$values :
$price :
Tags
deprecated
2.3.0

Coupons can not be applied after tax.

Return values
mixed

get_cart_discount_tax_total()

Get the total of all cart tax discounts (used for discounts on tax inclusive prices).

public get_cart_discount_tax_total() : float
Return values
float

get_cart_url()

Gets the url to the cart page.

public get_cart_url() : string
Tags
deprecated
2.5.0

in favor to wc_get_cart_url()

Return values
stringurl to page

get_checkout_url()

Gets the url to the checkout page.

public get_checkout_url() : string
Tags
deprecated
2.5.0

in favor to wc_get_checkout_url()

Return values
stringurl to page

get_discounted_price()

Function to apply discounts to a product and get the discounted price (before tax is applied).

public get_discounted_price(mixed $values, mixed $price[, bool $add_totals = false ]) : float
Parameters
$values : mixed

Cart item.

$price : mixed

Price of item.

$add_totals : bool = false

Legacy.

Tags
deprecated
3.2.0

Calculation and coupon logic is handled in WC_Cart_Totals.

Return values
floatprice

get_discounts_after_tax()

Gets the order discount amount - these are applied after tax.

public get_discounts_after_tax() : mixed
Tags
deprecated
2.3.0

Coupons can not be applied after tax.

Return values
mixed

get_discounts_before_tax()

Gets the total (product) discount amount - these are applied before tax.

public get_discounts_before_tax() : mixed
Tags
deprecated
2.3.0

Order discounts (after tax) removed in 2.3 so multiple methods for discounts are no longer required.

Return values
mixedformatted price or false if there are none.

get_order_discount_total()

Get the total of all order discounts (after tax discounts).

public get_order_discount_total() : int
Tags
deprecated
2.3.0

Order discounts (after tax) removed in 2.3.

Return values
int

remove_taxes()

Remove taxes.

public remove_taxes() : mixed
Tags
deprecated
3.2.0

Taxes are never calculated if customer is tax except making this function unused.

Return values
mixed

ship_to_billing_address_only()

Sees if we need a shipping address.

public ship_to_billing_address_only() : bool
Tags
deprecated
2.5.0

in favor to wc_ship_to_billing_address_only()

Return values
bool