WooCommerce Code Reference

WC_Cart extends WC_Legacy_Cart
in package

WC_Cart class.

Table of Contents

$applied_coupons  : array<string|int, mixed>
Contains an array of coupon codes applied to the cart.
$cart_contents  : array<string|int, mixed>
Contains an array of cart items.
$cart_session_data  : mixed
Array of defaults. Not used since 3.2.
$coupon_applied_count  : array<string|int, mixed>
Contains an array of coupon usage counts after they have been applied.
$removed_cart_contents  : array<string|int, mixed>
Contains an array of removed cart items so we can restore them if needed.
$default_totals  : array<string|int, mixed>
Total defaults used to reset.
$fees_api  : WC_Cart_Fees
Reference to the cart fees API class.
$session  : WC_Cart_Session
Reference to the cart session handling class.
$shipping_methods  : array<string|int, mixed>
This stores the chosen shipping methods for the cart item packages.
$totals  : array<string|int, mixed>
Store calculated totals.
__clone()  : mixed
When cloning, ensure object properties are handled.
__construct()  : mixed
Constructor for the cart class. Loads options and hooks in the init method.
__get()  : mixed
Magic getters.
__isset()  : mixed
Map legacy variables.
__set()  : mixed
Map legacy variables to setters.
add_discount()  : bool
Renamed for consistency.
add_fee()  : mixed
Add additional fee to the cart.
add_to_cart()  : string|bool
Add a product to the cart.
apply_cart_discounts_after_tax()  : mixed
Function to apply cart discounts after tax.
apply_coupon()  : bool
Applies a coupon code passed to the method.
apply_product_discounts_after_tax()  : mixed
Function to apply product discounts after tax.
calculate_fees()  : mixed
Trigger an action so 3rd parties can add custom fees.
calculate_shipping()  : mixed
Uses the shipping class to calculate shipping then gets the totals when its finished.
calculate_totals()  : mixed
Calculate totals for the items in the cart.
check_cart_coupons()  : mixed
Check cart coupons for errors.
check_cart_item_stock()  : bool|WP_Error
Looks through the cart to check each item is in stock. If not, add an error.
check_cart_item_validity()  : bool|WP_Error
Looks through cart items and checks the posts are not trashed or deleted.
check_cart_items()  : mixed
Check all cart items for errors.
check_customer_coupons()  : mixed
Check for user coupons (now that we have billing email). If a coupon is invalid, add an error.
coupons_enabled()  : bool
Coupons enabled function. Filterable.
display_prices_including_tax()  : bool
Return whether or not the cart is displaying prices including tax, rather than excluding tax.
empty_cart()  : mixed
Empties the cart and optionally the persistent cart too.
fees_api()  : WC_Cart_Fees
Return reference to fees API.
find_product_in_cart()  : string
Check if product is in the cart and return cart item key.
generate_cart_id()  : string
Generate a unique ID for the cart item being added.
get_applied_coupons()  : array<string|int, mixed>
Gets the array of applied coupon codes.
get_cart()  : array<string|int, mixed>
Returns the contents of the cart in an array.
get_cart_contents()  : array<string|int, mixed>
Gets cart contents.
get_cart_contents_count()  : int
Get number of items in the cart.
get_cart_contents_tax()  : float
Gets cart tax amount.
get_cart_contents_taxes()  : mixed
Get taxes.
get_cart_contents_total()  : float
Gets cart total. This is the total of items in the cart, but after discounts. Subtotal is before discounts.
get_cart_contents_weight()  : float
Get weight of items in the cart.
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_hash()  : string
Returns the hash based on cart contents.
get_cart_item()  : array<string|int, mixed>
Returns a specific item in the cart.
get_cart_item_quantities()  : array<string|int, mixed>
Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines.
get_cart_item_tax_classes()  : array<string|int, mixed>
Get all tax classes for items in the cart.
get_cart_item_tax_classes_for_shipping()  : array<string|int, mixed>
Get all tax classes for shipping based on the items in the cart.
get_cart_shipping_total()  : string
Gets the shipping total (after calculation).
get_cart_subtotal()  : string
Gets the sub total (after calculation).
get_cart_tax()  : string
Gets the cart tax (after calculation).
get_cart_total()  : string
Gets the cart contents total (after calculation).
get_cart_url()  : string
Gets the url to the cart page.
get_checkout_url()  : string
Gets the url to the checkout page.
get_coupon_discount_amount()  : float
Get the discount amount for a used coupon.
get_coupon_discount_tax_amount()  : float
Get the discount tax amount for a used coupon (for tax inclusive prices).
get_coupon_discount_tax_totals()  : array<string|int, mixed>
Return all calculated coupon tax totals.
get_coupon_discount_totals()  : array<string|int, mixed>
Return all calculated coupon totals.
get_coupons()  : array<string|int, mixed>
Get array of applied coupon objects and codes.
get_cross_sells()  : array<string|int, mixed>
Gets cross sells based on the items in the cart.
get_customer()  : WC_Customer
Get cart's owner.
get_discount_tax()  : float
Get discount_tax.
get_discount_total()  : float
Get discount_total.
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_displayed_subtotal()  : string
Determines the value that the customer spent and the subtotal displayed, used for things like coupon validation.
get_fee_tax()  : float
Get total fee tax amount.
get_fee_taxes()  : mixed
Get taxes.
get_fee_total()  : float
Get total fee amount.
get_fees()  : array<string|int, mixed>
Return all added fees from the Fees API.
get_item_data()  : string
Gets and formats a list of cart item data + variations for display on the frontend.
get_order_discount_total()  : int
Get the total of all order discounts (after tax discounts).
get_product_price()  : string
Get the product row price per item.
get_product_subtotal()  : string
Get the product row subtotal.
get_remove_url()  : string
Gets the url to remove an item from the cart.
get_removed_cart_contents()  : array<string|int, mixed>
Return items removed from the cart.
get_shipping_packages()  : array<string|int, mixed>
Get packages to calculate shipping for.
get_shipping_tax()  : float
Get shipping_tax.
get_shipping_tax_amount()  : float
Get a tax amount.
get_shipping_taxes()  : mixed
Get taxes.
get_shipping_total()  : float
Get shipping_total.
get_subtotal()  : float
Get subtotal.
get_subtotal_tax()  : float
Get subtotal_tax.
get_tax_amount()  : float
Get a tax amount.
get_tax_price_display_mode()  : string
Returns 'incl' if tax should be included in cart, otherwise returns 'excl'.
get_tax_totals()  : array<string|int, mixed>
Get taxes, merged by code, formatted ready for output.
get_taxes()  : array<string|int, mixed>
Returns the cart and shipping taxes, merged.
get_taxes_total()  : float
Get tax row amounts with or without compound taxes includes.
get_total()  : float|string
Gets cart total after calculation.
get_total_discount()  : mixed
Gets the total discount amount.
get_total_ex_tax()  : string
Gets the total excluding taxes.
get_total_tax()  : float
Get total tax amount.
get_totals()  : array<string|int, mixed>
Return all calculated totals.
get_undo_url()  : string
Gets the url to re-add an item into the cart.
has_discount()  : bool
Returns whether or not a discount has been applied.
init()  : mixed
Init.
is_coupon_emails_allowed()  : bool
Checks if the given email address(es) matches the ones specified on the coupon.
is_empty()  : bool
Checks if the cart is empty.
maybe_set_cart_cookies()  : mixed
needs_payment()  : bool
Looks at the totals to see if payment is actually required.
needs_shipping()  : bool
Looks through the cart to see if shipping is actually required.
needs_shipping_address()  : bool
Should the shipping address form be shown.
persistent_cart_destroy()  : mixed
persistent_cart_update()  : mixed
remove_cart_item()  : bool
Remove a cart item.
remove_coupon()  : bool
Remove a single coupon by code.
remove_coupons()  : mixed
Remove coupons from the cart of a defined type. Type 1 is before tax, type 2 is after tax.
remove_taxes()  : mixed
Remove taxes.
restore_cart_item()  : bool
Restore a cart item.
set_applied_coupons()  : mixed
Sets the array of applied coupon codes.
set_cart_contents()  : mixed
Sets the contents of the cart.
set_cart_contents_tax()  : mixed
Set cart tax amount.
set_cart_contents_taxes()  : mixed
Set taxes.
set_cart_contents_total()  : mixed
Set cart_contents_total.
set_coupon_discount_tax_totals()  : mixed
Sets the array of calculated coupon tax totals.
set_coupon_discount_totals()  : mixed
Sets the array of calculated coupon totals.
set_discount_tax()  : mixed
Set discount_tax.
set_discount_total()  : mixed
Set discount_total.
set_fee_tax()  : mixed
Set fee tax.
set_fee_taxes()  : mixed
Set taxes.
set_fee_total()  : mixed
Set fee amount.
set_quantity()  : bool
Set the quantity for an item in the cart using it's key.
set_removed_cart_contents()  : mixed
Set items removed from the cart.
set_session()  : mixed
set_shipping_tax()  : mixed
Set shipping_tax.
set_shipping_taxes()  : mixed
Set taxes.
set_shipping_total()  : mixed
Set shipping_total.
set_subtotal()  : mixed
Set subtotal.
set_subtotal_tax()  : mixed
Set subtotal.
set_total()  : mixed
Set cart total.
set_total_tax()  : mixed
Set total tax amount.
set_totals()  : mixed
Set all calculated totals.
ship_to_billing_address_only()  : bool
Sees if we need a shipping address.
show_shipping()  : bool
Sees if the customer has entered enough data to calc the shipping yet.
filter_items_needing_shipping()  : bool
Filter items needing shipping callback.
get_chosen_shipping_methods()  : array<string|int, mixed>
Given a set of packages with rates, get the chosen ones only.
get_items_needing_shipping()  : array<string|int, mixed>
Get only items that need shipping.
get_totals_var()  : mixed
Get a total.
reset_totals()  : mixed
Reset cart totals to the defaults. Useful before running calculations.

Properties

$applied_coupons

Contains an array of coupon codes applied to the cart.

public array<string|int, mixed> $applied_coupons = array()

$cart_contents

Contains an array of cart items.

public array<string|int, mixed> $cart_contents = array()

$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<string|int, mixed> $coupon_applied_count = array()
Tags
deprecated
3.2.0

$removed_cart_contents

Contains an array of removed cart items so we can restore them if needed.

public array<string|int, mixed> $removed_cart_contents = array()

$default_totals

Total defaults used to reset.

protected array<string|int, mixed> $default_totals = array('subtotal' => 0, 'subtotal_tax' => 0, 'shipping_total' => 0, 'shipping_tax' => 0, 'shipping_taxes' => array(), 'discount_total' => 0, 'discount_tax' => 0, 'cart_contents_total' => 0, 'cart_contents_tax' => 0, 'cart_contents_taxes' => array(), 'fee_total' => 0, 'fee_tax' => 0, 'fee_taxes' => array(), 'total' => 0, 'total_tax' => 0)

$shipping_methods

This stores the chosen shipping methods for the cart item packages.

protected array<string|int, mixed> $shipping_methods

Methods

__clone()

When cloning, ensure object properties are handled.

public __clone() : mixed

These properties store a reference to the cart, so we use new instead of clone.

Return values
mixed

__construct()

Constructor for the cart class. Loads options and hooks in the init method.

public __construct() : mixed
Return values
mixed

__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.

add_fee()

Add additional fee to the cart.

public add_fee(string $name, float $amount[, bool $taxable = false ][, string $tax_class = '' ]) : mixed

This method should be called on a callback attached to the woocommerce_cart_calculate_fees action during cart/checkout. Fees do not persist.

Parameters
$name : string

Unique name for the fee. Multiple fees of the same name cannot be added.

$amount : float

Fee amount (do not enter negative amounts).

$taxable : bool = false

Is the fee taxable? (default: false).

$tax_class : string = ''

The tax class for the fee if taxable. A blank string is standard tax class. (default: '').

Tags
uses
WC_Cart_Fees::add_fee
Return values
mixed

add_to_cart()

Add a product to the cart.

public add_to_cart(int $product_id[, int $quantity = 1 ], int $variation_id[, array<string|int, mixed> $variation = array() ][, array<string|int, mixed> $cart_item_data = array() ]) : string|bool
Parameters
$product_id : int

contains the id of the product to add to the cart.

$quantity : int = 1

contains the quantity of the item to add.

$variation_id : int

ID of the variation being added to the cart.

$variation : array<string|int, mixed> = array()

attribute values.

$cart_item_data : array<string|int, mixed> = array()

extra cart item data we want to pass into the item.

Tags
throws
Exception

Plugins can throw an exception to prevent adding to cart.

Return values
string|bool$cart_item_key

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_coupon()

Applies a coupon code passed to the method.

public apply_coupon(string $coupon_code) : bool
Parameters
$coupon_code : string
  • The code to apply.
Return values
boolTrue if the coupon is applied, false if it does not exist or cannot be applied.

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

calculate_fees()

Trigger an action so 3rd parties can add custom fees.

public calculate_fees() : mixed
Tags
since
2.0.0
Return values
mixed

calculate_shipping()

Uses the shipping class to calculate shipping then gets the totals when its finished.

public calculate_shipping() : mixed
Return values
mixed

check_cart_coupons()

Check cart coupons for errors.

public check_cart_coupons() : mixed
Return values
mixed

check_cart_item_stock()

Looks through the cart to check each item is in stock. If not, add an error.

public check_cart_item_stock() : bool|WP_Error
Return values
bool|WP_Error

check_cart_item_validity()

Looks through cart items and checks the posts are not trashed or deleted.

public check_cart_item_validity() : bool|WP_Error
Return values
bool|WP_Error

check_cart_items()

Check all cart items for errors.

public check_cart_items() : mixed
Return values
mixed

check_customer_coupons()

Check for user coupons (now that we have billing email). If a coupon is invalid, add an error.

public check_customer_coupons(array<string|int, mixed> $posted) : mixed

Checks two types of coupons:

  1. Where a list of customer emails are set (limits coupon usage to those defined).
  2. Where a usage_limit_per_user is set (limits coupon usage to a number based on user ID and email).
Parameters
$posted : array<string|int, mixed>

Post data.

Return values
mixed

display_prices_including_tax()

Return whether or not the cart is displaying prices including tax, rather than excluding tax.

public display_prices_including_tax() : bool
Tags
since
3.3.0
Return values
bool

empty_cart()

Empties the cart and optionally the persistent cart too.

public empty_cart([bool $clear_persistent_cart = true ]) : mixed
Parameters
$clear_persistent_cart : bool = true

Should the persistent cart be cleared too. Defaults to true.

Return values
mixed

find_product_in_cart()

Check if product is in the cart and return cart item key.

public find_product_in_cart([mixed $cart_id = false ]) : string

Cart item key will be unique based on the item and its properties, such as variations.

Parameters
$cart_id : mixed = false

id of product to find in the cart.

Return values
stringcart item key

generate_cart_id()

Generate a unique ID for the cart item being added.

public generate_cart_id(int $product_id, int $variation_id[, array<string|int, mixed> $variation = array() ][, array<string|int, mixed> $cart_item_data = array() ]) : string
Parameters
$product_id : int
  • id of the product the key is being generated for.
$variation_id : int

of the product the key is being generated for.

$variation : array<string|int, mixed> = array()

data for the cart item.

$cart_item_data : array<string|int, mixed> = array()

other cart item data passed which affects this items uniqueness in the cart.

Return values
stringcart item key

get_applied_coupons()

Gets the array of applied coupon codes.

public get_applied_coupons() : array<string|int, mixed>
Return values
array<string|int, mixed>of applied coupons

get_cart()

Returns the contents of the cart in an array.

public get_cart() : array<string|int, mixed>
Return values
array<string|int, mixed>contents of the cart

get_cart_contents()

Gets cart contents.

public get_cart_contents() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>of cart items

get_cart_contents_count()

Get number of items in the cart.

public get_cart_contents_count() : int
Return values
int

get_cart_contents_tax()

Gets cart tax amount.

public get_cart_contents_tax() : float
Tags
since
3.2.0
Return values
float

get_cart_contents_taxes()

Get taxes.

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

get_cart_contents_total()

Gets cart total. This is the total of items in the cart, but after discounts. Subtotal is before discounts.

public get_cart_contents_total() : float
Tags
since
3.2.0
Return values
float

get_cart_contents_weight()

Get weight of items in the cart.

public get_cart_contents_weight() : float
Tags
since
2.5.0
Return values
float

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_hash()

Returns the hash based on cart contents.

public get_cart_hash() : string
Tags
since
3.6.0
Return values
stringhash for cart content

get_cart_item()

Returns a specific item in the cart.

public get_cart_item(string $item_key) : array<string|int, mixed>
Parameters
$item_key : string

Cart item key.

Return values
array<string|int, mixed>Item data

get_cart_item_quantities()

Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines.

public get_cart_item_quantities() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_cart_item_tax_classes()

Get all tax classes for items in the cart.

public get_cart_item_tax_classes() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_cart_item_tax_classes_for_shipping()

Get all tax classes for shipping based on the items in the cart.

public get_cart_item_tax_classes_for_shipping() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_cart_shipping_total()

Gets the shipping total (after calculation).

public get_cart_shipping_total() : string
Return values
stringprice or string for the shipping total

get_cart_subtotal()

Gets the sub total (after calculation).

public get_cart_subtotal([bool $compound = false ]) : string
Parameters
$compound : bool = false

whether to include compound taxes.

Return values
stringformatted price

get_cart_tax()

Gets the cart tax (after calculation).

public get_cart_tax() : string
Return values
stringformatted price

get_cart_total()

Gets the cart contents total (after calculation).

public get_cart_total() : string
Return values
stringformatted price

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_coupon_discount_amount()

Get the discount amount for a used coupon.

public get_coupon_discount_amount(string $code[, bool $ex_tax = true ]) : float
Parameters
$code : string

coupon code.

$ex_tax : bool = true

inc or ex tax.

Return values
floatdiscount amount

get_coupon_discount_tax_amount()

Get the discount tax amount for a used coupon (for tax inclusive prices).

public get_coupon_discount_tax_amount(string $code) : float
Parameters
$code : string

coupon code.

Return values
floatdiscount amount

get_coupon_discount_tax_totals()

Return all calculated coupon tax totals.

public get_coupon_discount_tax_totals() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>

get_coupon_discount_totals()

Return all calculated coupon totals.

public get_coupon_discount_totals() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>

get_coupons()

Get array of applied coupon objects and codes.

public get_coupons([null $deprecated = null ]) : array<string|int, mixed>
Parameters
$deprecated : null = null

No longer used.

Return values
array<string|int, mixed>of applied coupons

get_cross_sells()

Gets cross sells based on the items in the cart.

public get_cross_sells() : array<string|int, mixed>
Return values
array<string|int, mixed>cross_sells (item ids)

get_discount_tax()

Get discount_tax.

public get_discount_tax() : float
Tags
since
3.2.0
Return values
float

get_discount_total()

Get discount_total.

public get_discount_total() : float
Tags
since
3.2.0
Return values
float

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_displayed_subtotal()

Determines the value that the customer spent and the subtotal displayed, used for things like coupon validation.

public get_displayed_subtotal() : string

Since the coupon lines are displayed based on the TAX DISPLAY value of cart, this is used to determine the spend.

If cart totals are shown including tax, use the subtotal. If cart totals are shown excluding tax, use the subtotal ex tax (tax is shown after coupons).

Tags
since
2.6.0
Return values
string

get_fee_tax()

Get total fee tax amount.

public get_fee_tax() : float
Tags
since
3.2.0
Return values
float

get_fee_taxes()

Get taxes.

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

get_fee_total()

Get total fee amount.

public get_fee_total() : float
Tags
since
3.2.0
Return values
float

get_fees()

Return all added fees from the Fees API.

public get_fees() : array<string|int, mixed>
Tags
uses
WC_Cart_Fees::get_fees
Return values
array<string|int, mixed>

get_item_data()

Gets and formats a list of cart item data + variations for display on the frontend.

public get_item_data(array<string|int, mixed> $cart_item[, bool $flat = false ]) : string
Parameters
$cart_item : array<string|int, mixed>

Cart item object.

$flat : bool = false

Should the data be returned flat or in a list.

Return values
string

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

get_product_price()

Get the product row price per item.

public get_product_price(WC_Product $product) : string
Parameters
$product : WC_Product

Product object.

Return values
stringformatted price

get_product_subtotal()

Get the product row subtotal.

public get_product_subtotal(WC_Product $product, int $quantity) : string

Gets the tax etc to avoid rounding issues.

When on the checkout (review order), this will get the subtotal based on the customer's tax rate rather than the base rate.

Parameters
$product : WC_Product

Product object.

$quantity : int

Quantity being purchased.

Return values
stringformatted price

get_remove_url()

Gets the url to remove an item from the cart.

public get_remove_url(string $cart_item_key) : string
Parameters
$cart_item_key : string

contains the id of the cart item.

Return values
stringurl to page

get_removed_cart_contents()

Return items removed from the cart.

public get_removed_cart_contents() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>

get_shipping_packages()

Get packages to calculate shipping for.

public get_shipping_packages() : array<string|int, mixed>

This lets us calculate costs for carts that are shipped to multiple locations.

Shipping methods are responsible for looping through these packages.

By default we pass the cart itself as a package - plugins can change this. through the filter and break it up.

Tags
since
1.5.4
Return values
array<string|int, mixed>of cart items

get_shipping_tax()

Get shipping_tax.

public get_shipping_tax() : float
Tags
since
3.2.0
Return values
float

get_shipping_tax_amount()

Get a tax amount.

public get_shipping_tax_amount(string $tax_rate_id) : float
Parameters
$tax_rate_id : string

ID of the tax rate to get taxes for.

Return values
floatamount

get_shipping_taxes()

Get taxes.

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

get_shipping_total()

Get shipping_total.

public get_shipping_total() : float
Tags
since
3.2.0
Return values
float

get_subtotal()

Get subtotal.

public get_subtotal() : float
Tags
since
3.2.0
Return values
float

get_subtotal_tax()

Get subtotal_tax.

public get_subtotal_tax() : float
Tags
since
3.2.0
Return values
float

get_tax_amount()

Get a tax amount.

public get_tax_amount(string $tax_rate_id) : float
Parameters
$tax_rate_id : string

ID of the tax rate to get taxes for.

Return values
floatamount

get_tax_price_display_mode()

Returns 'incl' if tax should be included in cart, otherwise returns 'excl'.

public get_tax_price_display_mode() : string
Return values
string

get_tax_totals()

Get taxes, merged by code, formatted ready for output.

public get_tax_totals() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_taxes()

Returns the cart and shipping taxes, merged.

public get_taxes() : array<string|int, mixed>
Return values
array<string|int, mixed>merged taxes

get_taxes_total()

Get tax row amounts with or without compound taxes includes.

public get_taxes_total([bool $compound = true ][, bool $display = true ]) : float
Parameters
$compound : bool = true

True if getting compound taxes.

$display : bool = true

True if getting total to display.

Return values
floatprice

get_total()

Gets cart total after calculation.

public get_total([string $context = 'view' ]) : float|string
Parameters
$context : string = 'view'

If the context is view, the value will be formatted for display. This keeps it compatible with pre-3.2 versions.

Tags
since
3.2.0
Return values
float|string

get_total_discount()

Gets the total discount amount.

public get_total_discount() : mixed
Return values
mixedformatted price or false if there are none

get_total_ex_tax()

Gets the total excluding taxes.

public get_total_ex_tax() : string
Return values
stringformatted price

get_total_tax()

Get total tax amount.

public get_total_tax() : float
Tags
since
3.2.0
Return values
float

get_totals()

Return all calculated totals.

public get_totals() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>

get_undo_url()

Gets the url to re-add an item into the cart.

public get_undo_url(string $cart_item_key) : string
Parameters
$cart_item_key : string

Cart item key to undo.

Return values
stringurl to page

has_discount()

Returns whether or not a discount has been applied.

public has_discount([string $coupon_code = '' ]) : bool
Parameters
$coupon_code : string = ''

Coupon code to check.

Return values
bool

is_coupon_emails_allowed()

Checks if the given email address(es) matches the ones specified on the coupon.

public is_coupon_emails_allowed(array<string|int, mixed> $check_emails, array<string|int, mixed> $restrictions) : bool
Parameters
$check_emails : array<string|int, mixed>

Array of customer email addresses.

$restrictions : array<string|int, mixed>

Array of allowed email addresses.

Tags
deprecated
9.0.0

In favor of static method Automattic\WooCommerce\Utilities\DiscountsUtil::is_coupon_emails_allowed.

Return values
bool

needs_payment()

Looks at the totals to see if payment is actually required.

public needs_payment() : bool
Return values
bool

needs_shipping()

Looks through the cart to see if shipping is actually required.

public needs_shipping() : bool
Return values
boolwhether or not the cart needs shipping

needs_shipping_address()

Should the shipping address form be shown.

public needs_shipping_address() : bool
Return values
bool

remove_cart_item()

Remove a cart item.

public remove_cart_item(string $cart_item_key) : bool
Parameters
$cart_item_key : string

Cart item key to remove from the cart.

Tags
since
2.3.0
Return values
bool

remove_coupon()

Remove a single coupon by code.

public remove_coupon(string $coupon_code) : bool
Parameters
$coupon_code : string

Code of the coupon to remove.

Return values
bool

remove_coupons()

Remove coupons from the cart of a defined type. Type 1 is before tax, type 2 is after tax.

public remove_coupons([null $deprecated = null ]) : mixed
Parameters
$deprecated : null = null

No longer used.

Return values
mixed

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

restore_cart_item()

Restore a cart item.

public restore_cart_item(string $cart_item_key) : bool
Parameters
$cart_item_key : string

Cart item key to restore to the cart.

Return values
bool

set_applied_coupons()

Sets the array of applied coupon codes.

public set_applied_coupons([array<string|int, mixed> $value = array() ]) : mixed
Parameters
$value : array<string|int, mixed> = array()

List of applied coupon codes.

Return values
mixed

set_cart_contents()

Sets the contents of the cart.

public set_cart_contents(array<string|int, mixed> $value) : mixed
Parameters
$value : array<string|int, mixed>

Cart array.

Return values
mixed

set_cart_contents_tax()

Set cart tax amount.

public set_cart_contents_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_cart_contents_taxes()

Set taxes.

public set_cart_contents_taxes(array<string|int, mixed> $value) : mixed
Parameters
$value : array<string|int, mixed>

Tax values.

Tags
since
3.2.0
Return values
mixed

set_cart_contents_total()

Set cart_contents_total.

public set_cart_contents_total(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_coupon_discount_tax_totals()

Sets the array of calculated coupon tax totals.

public set_coupon_discount_tax_totals([array<string|int, mixed> $value = array() ]) : mixed
Parameters
$value : array<string|int, mixed> = array()

Value to set.

Tags
since
3.2.0
Return values
mixed

set_coupon_discount_totals()

Sets the array of calculated coupon totals.

public set_coupon_discount_totals([array<string|int, mixed> $value = array() ]) : mixed
Parameters
$value : array<string|int, mixed> = array()

Value to set.

Tags
since
3.2.0
Return values
mixed

set_discount_tax()

Set discount_tax.

public set_discount_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_discount_total()

Set discount_total.

public set_discount_total(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_fee_tax()

Set fee tax.

public set_fee_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_fee_taxes()

Set taxes.

public set_fee_taxes(array<string|int, mixed> $value) : mixed
Parameters
$value : array<string|int, mixed>

Tax values.

Tags
since
3.2.0
Return values
mixed

set_fee_total()

Set fee amount.

public set_fee_total(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_quantity()

Set the quantity for an item in the cart using it's key.

public set_quantity(string $cart_item_key[, int $quantity = 1 ][, bool $refresh_totals = true ]) : bool
Parameters
$cart_item_key : string

contains the id of the cart item.

$quantity : int = 1

contains the quantity of the item.

$refresh_totals : bool = true

whether or not to calculate totals after setting the new qty. Can be used to defer calculations if setting quantities in bulk.

Return values
bool

set_removed_cart_contents()

Set items removed from the cart.

public set_removed_cart_contents([array<string|int, mixed> $value = array() ]) : mixed
Parameters
$value : array<string|int, mixed> = array()

Item array.

Tags
since
3.2.0
Return values
mixed

set_shipping_tax()

Set shipping_tax.

public set_shipping_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_shipping_taxes()

Set taxes.

public set_shipping_taxes(array<string|int, mixed> $value) : mixed
Parameters
$value : array<string|int, mixed>

Tax values.

Tags
since
3.2.0
Return values
mixed

set_shipping_total()

Set shipping_total.

public set_shipping_total(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_subtotal()

Set subtotal.

public set_subtotal(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_subtotal_tax()

Set subtotal.

public set_subtotal_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_total()

Set cart total.

public set_total(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_total_tax()

Set total tax amount.

public set_total_tax(string $value) : mixed
Parameters
$value : string

Value to set.

Tags
since
3.2.0
Return values
mixed

set_totals()

Set all calculated totals.

public set_totals([array<string|int, mixed> $value = array() ]) : mixed
Parameters
$value : array<string|int, mixed> = array()

Value to set.

Tags
since
3.2.0
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

show_shipping()

Sees if the customer has entered enough data to calc the shipping yet.

public show_shipping() : bool
Return values
bool

filter_items_needing_shipping()

Filter items needing shipping callback.

protected filter_items_needing_shipping(array<string|int, mixed> $item) : bool
Parameters
$item : array<string|int, mixed>

Item to check for shipping.

Tags
since
3.0.0
Return values
bool

get_chosen_shipping_methods()

Given a set of packages with rates, get the chosen ones only.

protected get_chosen_shipping_methods([array<string|int, mixed> $calculated_shipping_packages = array() ]) : array<string|int, mixed>
Parameters
$calculated_shipping_packages : array<string|int, mixed> = array()

Array of packages.

Tags
since
3.2.0
Return values
array<string|int, mixed>

get_items_needing_shipping()

Get only items that need shipping.

protected get_items_needing_shipping() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_totals_var()

Get a total.

protected get_totals_var(string $key) : mixed
Parameters
$key : string

Key of element in $totals array.

Tags
since
3.2.0
Return values
mixed

reset_totals()

Reset cart totals to the defaults. Useful before running calculations.

private reset_totals() : mixed
Return values
mixed