WC_Cart
extends WC_Legacy_Cart
in package
WC_Cart class.
Table of Contents
- $applied_coupons : array
- Contains an array of coupon codes applied to the cart.
- $cart_contents : array
- Contains an array of cart items.
- $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.
- $removed_cart_contents : array
- Contains an array of removed cart items so we can restore them if needed.
- $default_totals : array
- 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
- This stores the chosen shipping methods for the cart item packages.
- $totals : array
- 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
- Gets the array of applied coupon codes.
- get_cart() : array
- Returns the contents of the cart in an array.
- get_cart_contents() : array
- 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
- Returns a specific item in the cart.
- get_cart_item_quantities() : array
- Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines.
- get_cart_item_tax_classes() : array
- Get all tax classes for items in the cart.
- get_cart_item_tax_classes_for_shipping() : array
- 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
- Return all calculated coupon tax totals.
- get_coupon_discount_totals() : array
- Return all calculated coupon totals.
- get_coupons() : array
- Get array of applied coupon objects and codes.
- get_cross_sells() : array
- 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
- 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
- Return items removed from the cart.
- get_shipping_packages() : array
- 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.
- 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
- Get taxes, merged by code, formatted ready for output.
- get_taxes() : array
- Returns the cart and shipping taxes, merged.
- get_taxes_total() : float
- Get tax row amounts with or without compound taxes includes.
- get_total() : float
- 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
- 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
- Given a set of packages with rates, get the chosen ones only.
- get_items_needing_shipping() : array
- 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
$applied_coupons
= array()
$cart_contents
Contains an array of cart items.
public
array
$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
$coupon_applied_count
Contains an array of coupon usage counts after they have been applied.
public
array
$coupon_applied_count
= array()
Tags
$removed_cart_contents
Contains an array of removed cart items so we can restore them if needed.
public
array
$removed_cart_contents
= array()
$default_totals
Total defaults used to reset.
protected
array
$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)
$fees_api
Reference to the cart fees API class.
protected
WC_Cart_Fees
$fees_api
$session
Reference to the cart session handling class.
protected
WC_Cart_Session
$session
$shipping_methods
This stores the chosen shipping methods for the cart item packages.
protected
array
$shipping_methods
$totals
Store calculated totals.
protected
array
$totals
= array()
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__isset()
Map legacy variables.
public
__isset(string $name) : mixed
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
mixedadd_discount()
Renamed for consistency.
public
add_discount(string $coupon_code) : bool
Parameters
- $coupon_code : string
Return values
bool — True 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
Return values
mixedadd_to_cart()
Add a product to the cart.
public
add_to_cart(int $product_id[, int $quantity = 1 ], int $variation_id[, array $variation = array() ][, array $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 = array()
-
attribute values.
- $cart_item_data : array = array()
-
extra cart item data we want to pass into the item.
Tags
Return values
string|bool — $cart_item_keyapply_cart_discounts_after_tax()
Function to apply cart discounts after tax.
public
apply_cart_discounts_after_tax( $values, $price) : mixed
Parameters
Tags
Return values
mixedapply_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
bool — True 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
Tags
Return values
mixedcalculate_fees()
Trigger an action so 3rd parties can add custom fees.
public
calculate_fees() : mixed
Tags
Return values
mixedcalculate_shipping()
Uses the shipping class to calculate shipping then gets the totals when its finished.
public
calculate_shipping() : mixed
Return values
mixedcalculate_totals()
Calculate totals for the items in the cart.
public
calculate_totals() : mixed
Tags
Return values
mixedcheck_cart_coupons()
Check cart coupons for errors.
public
check_cart_coupons() : mixed
Return values
mixedcheck_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_Errorcheck_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_Errorcheck_cart_items()
Check all cart items for errors.
public
check_cart_items() : mixed
Return values
mixedcheck_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 $posted) : mixed
Checks two types of coupons:
- Where a list of customer emails are set (limits coupon usage to those defined).
- Where a usage_limit_per_user is set (limits coupon usage to a number based on user ID and email).
Parameters
- $posted : array
-
Post data.
Return values
mixedcoupons_enabled()
Coupons enabled function. Filterable.
public
coupons_enabled() : bool
Tags
Return values
booldisplay_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
Return values
boolempty_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 persistant cart be cleared too. Defaults to true.
Return values
mixedfees_api()
Return reference to fees API.
public
fees_api() : WC_Cart_Fees
Tags
Return values
WC_Cart_Feesfind_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
string — cart item keygenerate_cart_id()
Generate a unique ID for the cart item being added.
public
generate_cart_id(int $product_id, int $variation_id[, array $variation = array() ][, array $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 = array()
-
data for the cart item.
- $cart_item_data : array = array()
-
other cart item data passed which affects this items uniqueness in the cart.
Return values
string — cart item keyget_applied_coupons()
Gets the array of applied coupon codes.
public
get_applied_coupons() : array
Return values
array — of applied couponsget_cart()
Returns the contents of the cart in an array.
public
get_cart() : array
Return values
array — contents of the cartget_cart_contents()
Gets cart contents.
public
get_cart_contents() : array
Tags
Return values
array — of cart itemsget_cart_contents_count()
Get number of items in the cart.
public
get_cart_contents_count() : int
Return values
intget_cart_contents_tax()
Gets cart tax amount.
public
get_cart_contents_tax() : float
Tags
Return values
floatget_cart_contents_taxes()
Get taxes.
public
get_cart_contents_taxes() : mixed
Tags
Return values
mixedget_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
Return values
floatget_cart_contents_weight()
Get weight of items in the cart.
public
get_cart_contents_weight() : float
Tags
Return values
floatget_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
floatget_cart_discount_total()
Get the total of all cart discounts.
public
get_cart_discount_total() : float
Return values
floatget_cart_for_session()
public
get_cart_for_session() : mixed
Return values
mixedget_cart_from_session()
Methods moved to session class in 3.2.0.
public
get_cart_from_session() : mixed
Return values
mixedget_cart_hash()
Returns the hash based on cart contents.
public
get_cart_hash() : string
Tags
Return values
string — hash for cart contentget_cart_item()
Returns a specific item in the cart.
public
get_cart_item(string $item_key) : array
Parameters
- $item_key : string
-
Cart item key.
Return values
array — Item dataget_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
Return values
arrayget_cart_item_tax_classes()
Get all tax classes for items in the cart.
public
get_cart_item_tax_classes() : array
Return values
arrayget_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
Return values
arrayget_cart_shipping_total()
Gets the shipping total (after calculation).
public
get_cart_shipping_total() : string
Return values
string — price or string for the shipping totalget_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
string — formatted priceget_cart_tax()
Gets the cart tax (after calculation).
public
get_cart_tax() : string
Return values
string — formatted priceget_cart_total()
Gets the cart contents total (after calculation).
public
get_cart_total() : string
Return values
string — formatted priceget_cart_url()
Gets the url to the cart page.
public
get_cart_url() : string
Tags
Return values
string — url to pageget_checkout_url()
Gets the url to the checkout page.
public
get_checkout_url() : string
Tags
Return values
string — url to pageget_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
float — discount amountget_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
float — discount amountget_coupon_discount_tax_totals()
Return all calculated coupon tax totals.
public
get_coupon_discount_tax_totals() : array
Tags
Return values
arrayget_coupon_discount_totals()
Return all calculated coupon totals.
public
get_coupon_discount_totals() : array
Tags
Return values
arrayget_coupons()
Get array of applied coupon objects and codes.
public
get_coupons([null $deprecated = null ]) : array
Parameters
- $deprecated : null = null
-
No longer used.
Return values
array — of applied couponsget_cross_sells()
Gets cross sells based on the items in the cart.
public
get_cross_sells() : array
Return values
array — cross_sells (item ids)get_customer()
Get cart's owner.
public
get_customer() : WC_Customer
Tags
Return values
WC_Customerget_discount_tax()
Get discount_tax.
public
get_discount_tax() : float
Tags
Return values
floatget_discount_total()
Get discount_total.
public
get_discount_total() : float
Tags
Return values
floatget_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
Return values
float — priceget_discounts_after_tax()
Gets the order discount amount - these are applied after tax.
public
get_discounts_after_tax() : mixed
Tags
Return values
mixedget_discounts_before_tax()
Gets the total (product) discount amount - these are applied before tax.
public
get_discounts_before_tax() : mixed
Tags
Return values
mixed — formatted 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
Return values
stringget_fee_tax()
Get total fee tax amount.
public
get_fee_tax() : float
Tags
Return values
floatget_fee_taxes()
Get taxes.
public
get_fee_taxes() : mixed
Tags
Return values
mixedget_fee_total()
Get total fee amount.
public
get_fee_total() : float
Tags
Return values
floatget_fees()
Return all added fees from the Fees API.
public
get_fees() : array
Tags
Return values
arrayget_item_data()
Gets and formats a list of cart item data + variations for display on the frontend.
public
get_item_data(array $cart_item[, bool $flat = false ]) : string
Parameters
- $cart_item : array
-
Cart item object.
- $flat : bool = false
-
Should the data be returned flat or in a list.
Return values
stringget_order_discount_total()
Get the total of all order discounts (after tax discounts).
public
get_order_discount_total() : int
Tags
Return values
intget_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
string — formatted priceget_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
string — formatted priceget_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
string — url to pageget_removed_cart_contents()
Return items removed from the cart.
public
get_removed_cart_contents() : array
Tags
Return values
arrayget_shipping_packages()
Get packages to calculate shipping for.
public
get_shipping_packages() : array
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
Return values
array — of cart itemsget_shipping_tax()
Get shipping_tax.
public
get_shipping_tax() : float
Tags
Return values
floatget_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
float — amountget_shipping_taxes()
Get taxes.
public
get_shipping_taxes() : mixed
Tags
Return values
mixedget_shipping_total()
Get shipping_total.
public
get_shipping_total() : float
Tags
Return values
floatget_subtotal()
Get subtotal.
public
get_subtotal() : float
Tags
Return values
floatget_subtotal_tax()
Get subtotal.
public
get_subtotal_tax() : float
Tags
Return values
floatget_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
float — amountget_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
stringget_tax_totals()
Get taxes, merged by code, formatted ready for output.
public
get_tax_totals() : array
Return values
arrayget_taxes()
Returns the cart and shipping taxes, merged.
public
get_taxes() : array
Return values
array — merged taxesget_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
float — priceget_total()
Gets cart total after calculation.
public
get_total([string $context = 'view' ]) : float
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
Return values
floatget_total_discount()
Gets the total discount amount.
public
get_total_discount() : mixed
Return values
mixed — formatted price or false if there are noneget_total_ex_tax()
Gets the total excluding taxes.
public
get_total_ex_tax() : string
Return values
string — formatted priceget_total_tax()
Get total tax amount.
public
get_total_tax() : float
Tags
Return values
floatget_totals()
Return all calculated totals.
public
get_totals() : array
Tags
Return values
arrayget_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
string — url to pagehas_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
boolinit()
Init.
public
init() : mixed
Tags
Return values
mixedis_coupon_emails_allowed()
Checks if the given email address(es) matches the ones specified on the coupon.
public
is_coupon_emails_allowed(array $check_emails, array $restrictions) : bool
Parameters
- $check_emails : array
-
Array of customer email addresses.
- $restrictions : array
-
Array of allowed email addresses.
Return values
boolis_empty()
Checks if the cart is empty.
public
is_empty() : bool
Return values
boolmaybe_set_cart_cookies()
public
maybe_set_cart_cookies() : mixed
Return values
mixedneeds_payment()
Looks at the totals to see if payment is actually required.
public
needs_payment() : bool
Return values
boolneeds_shipping()
Looks through the cart to see if shipping is actually required.
public
needs_shipping() : bool
Return values
bool — whether or not the cart needs shippingneeds_shipping_address()
Should the shipping address form be shown.
public
needs_shipping_address() : bool
Return values
boolpersistent_cart_destroy()
public
persistent_cart_destroy() : mixed
Return values
mixedpersistent_cart_update()
public
persistent_cart_update() : mixed
Return values
mixedremove_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
Return values
boolremove_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
boolremove_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
mixedremove_taxes()
Remove taxes.
public
remove_taxes() : mixed
Tags
Return values
mixedrestore_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
boolset_applied_coupons()
Sets the array of applied coupon codes.
public
set_applied_coupons([array $value = array() ]) : mixed
Parameters
- $value : array = array()
-
List of applied coupon codes.
Return values
mixedset_cart_contents()
Sets the contents of the cart.
public
set_cart_contents(array $value) : mixed
Parameters
- $value : array
-
Cart array.
Return values
mixedset_cart_contents_tax()
Set cart tax amount.
public
set_cart_contents_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_cart_contents_taxes()
Set taxes.
public
set_cart_contents_taxes(array $value) : mixed
Parameters
- $value : array
-
Tax values.
Tags
Return values
mixedset_cart_contents_total()
Set cart_contents_total.
public
set_cart_contents_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_coupon_discount_tax_totals()
Sets the array of calculated coupon tax totals.
public
set_coupon_discount_tax_totals([array $value = array() ]) : mixed
Parameters
- $value : array = array()
-
Value to set.
Tags
Return values
mixedset_coupon_discount_totals()
Sets the array of calculated coupon totals.
public
set_coupon_discount_totals([array $value = array() ]) : mixed
Parameters
- $value : array = array()
-
Value to set.
Tags
Return values
mixedset_discount_tax()
Set discount_tax.
public
set_discount_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_discount_total()
Set discount_total.
public
set_discount_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_fee_tax()
Set fee tax.
public
set_fee_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_fee_taxes()
Set taxes.
public
set_fee_taxes(array $value) : mixed
Parameters
- $value : array
-
Tax values.
Tags
Return values
mixedset_fee_total()
Set fee amount.
public
set_fee_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_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
boolset_removed_cart_contents()
Set items removed from the cart.
public
set_removed_cart_contents([array $value = array() ]) : mixed
Parameters
- $value : array = array()
-
Item array.
Tags
Return values
mixedset_session()
public
set_session() : mixed
Return values
mixedset_shipping_tax()
Set shipping_tax.
public
set_shipping_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_shipping_taxes()
Set taxes.
public
set_shipping_taxes(array $value) : mixed
Parameters
- $value : array
-
Tax values.
Tags
Return values
mixedset_shipping_total()
Set shipping_total.
public
set_shipping_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_subtotal()
Set subtotal.
public
set_subtotal(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_subtotal_tax()
Set subtotal.
public
set_subtotal_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_total()
Set cart total.
public
set_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_total_tax()
Set total tax amount.
public
set_total_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixedset_totals()
Set all calculated totals.
public
set_totals([array $value = array() ]) : mixed
Parameters
- $value : array = array()
-
Value to set.
Tags
Return values
mixedship_to_billing_address_only()
Sees if we need a shipping address.
public
ship_to_billing_address_only() : bool
Tags
Return values
boolshow_shipping()
Sees if the customer has entered enough data to calc the shipping yet.
public
show_shipping() : bool
Return values
boolfilter_items_needing_shipping()
Filter items needing shipping callback.
protected
filter_items_needing_shipping(array $item) : bool
Parameters
- $item : array
-
Item to check for shipping.
Tags
Return values
boolget_chosen_shipping_methods()
Given a set of packages with rates, get the chosen ones only.
protected
get_chosen_shipping_methods([array $calculated_shipping_packages = array() ]) : array
Parameters
- $calculated_shipping_packages : array = array()
-
Array of packages.
Tags
Return values
arrayget_items_needing_shipping()
Get only items that need shipping.
protected
get_items_needing_shipping() : array
Tags
Return values
arrayget_totals_var()
Get a total.
protected
get_totals_var(string $key) : mixed
Parameters
- $key : string
-
Key of element in $totals array.
Tags
Return values
mixedreset_totals()
Reset cart totals to the defaults. Useful before running calculations.
private
reset_totals() : mixed