Property | Type | Description | |
---|---|---|---|
$applied_coupons | Contains an array of coupon codes applied to the cart. | ||
$cart_contents | Contains an array of cart items. | ||
$cart_contents_total | The total cost of the cart items. | ||
$cart_session_data | cart_session_data. Array of data the cart calculates and stores in the session with defaults | ||
$coupon_applied_count | Contains an array of coupon usage counts after they have been applied. | ||
$coupon_discount_amounts | Contains an array of coupon code discounts after they have been applied. | ||
$coupon_discount_tax_amounts | Contains an array of coupon code discount taxes. Used for tax incl pricing. | ||
$coupons | Array of coupons | ||
$discount_cart | Discount amount before tax | ||
$discount_cart_tax | Discounted tax amount. Used predominantly for displaying tax inclusive prices correctly | ||
$fee_total | Total for additional fees. | ||
$fees | array | An array of fees. | |
$removed_cart_contents | Contains an array of removed cart items. | ||
$shipping_tax_total | Shipping tax. | ||
$shipping_taxes | An array of taxes/tax rates for the shipping. | ||
$shipping_total | Shipping cost. | ||
$subtotal | Cart subtotal. | ||
$subtotal_ex_tax | Cart subtotal without tax. | ||
$tax_total | Total cart tax. | ||
$taxes | An array of taxes/tax rates for the cart. | ||
$total | Cart grand total. |
Method | Description | |
---|---|---|
__construct ( ) | Constructor for the cart class. Loads options and hooks in the init method. | |
__get ( mixed $key ) : mixed | Auto-load in-accessible properties on demand. | |
add_discount ( string $coupon_code ) : boolean | Applies a coupon code passed to the method. | |
add_fee ( string $name, float $amount, boolean $taxable = false, string $tax_class = '' ) | Add additional fee to the cart. | |
add_to_cart ( integer $product_id, integer $quantity = 1, integer $variation_id, array $variation = [], array $cart_item_data = [] ) : string | boolean | Add a product to the cart. | |
apply_cart_discounts_after_tax ( $values, $price ) | Function to apply cart discounts after tax. | |
apply_product_discounts_after_tax ( $values, $price ) | Function to apply product discounts after tax. | |
calculate_fees ( ) | Calculate fees. | |
calculate_shipping ( ) | Uses the shipping class to calculate shipping then gets the totals when its finished. | |
calculate_totals ( ) | Calculate totals for the items in the cart. | |
check_cart_coupons ( ) | Check cart coupons for errors. | |
check_cart_item_stock ( ) : boolean | WP_Error | Looks through the cart to check each item is in stock. If not, add an error. | |
check_cart_item_validity ( ) : boolean | WP_Error | Looks through cart items and checks the posts are not trashed or deleted. | |
check_cart_items ( ) | Check all cart items for errors. | |
check_customer_coupons ( array $posted ) | Check for user coupons (now that we have billing email). If a coupon is invalid, add an error. | |
coupons_enabled ( ) : boolean | Coupons enabled function. Filterable. | |
empty_cart ( boolean $clear_persistent_cart = true ) | Empties the cart and optionally the persistent cart too. | |
find_product_in_cart ( $cart_id = false ) : string | Check if product is in the cart and return cart item key. | |
generate_cart_id ( integer $product_id, integer $variation_id, array $variation = [], array $cart_item_data = [] ) : 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_count ( ) : integer | Get number of items in the cart. | |
get_cart_contents_weight ( ) : integer | 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 ( ) : array | Returns the contents of the cart in an array without the 'data' element. | |
get_cart_from_session ( ) | Get the cart data from the PHP session and store it in class variables. | |
get_cart_item ( string $item_key ) : 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_shipping_total ( ) : string | Gets the shipping total (after calculation). | |
get_cart_subtotal ( boolean $compound = false ) : 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 ( string $code, boolean $ex_tax = true ) : float | Get the discount amount for a used coupon. | |
get_coupon_discount_tax_amount ( string $code ) : float | Get the discount tax amount for a used coupon (for tax inclusive prices). | |
get_coupons ( $deprecated = null ) : array | Get array of applied coupon objects and codes. | |
get_cross_sells ( ) : array | Gets cross sells based on the items in the cart. | |
get_discounted_price ( mixed $values, mixed $price, boolean $add_totals = false ) : float | Function to apply discounts to a product and get the discounted price (before tax is applied). | |
get_discounts_after_tax ( ) | 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_fees ( ) : array | Get fees. | |
get_item_data ( array $cart_item, boolean $flat = false ) : string | Gets and formats a list of cart item data + variations for display on the frontend. | |
get_order_discount_total ( ) : integer | Get the total of all order discounts (after tax discounts). | |
get_product_price ( WC_Product $product ) : string | Get the product row price per item. | |
get_product_subtotal ( WC_Product $product, integer $quantity ) : string | Get the product row subtotal. | |
get_remove_url ( string $cart_item_key ) : string | Gets the url to remove an item from the cart. | |
get_shipping_packages ( ) : array | Get packages to calculate shipping for. | |
get_shipping_tax_amount ( string $tax_rate_id ) : float | Get a tax amount. | |
get_tax_amount ( string $tax_rate_id ) : float | Get a tax amount. | |
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 ( boolean $compound = true, boolean $display = true ) : float | Get tax row amounts with or without compound taxes includes. | |
get_total ( ) : string | Gets the order total (after calculation). | |
get_total_discount ( ) : mixed | Gets the total discount amount - both kinds. | |
get_total_ex_tax ( ) : string | Gets the total excluding taxes. | |
get_undo_url ( string $cart_item_key ) : string | Gets the url to re-add an item into the cart. | |
has_discount ( string $coupon_code = '' ) : boolean | Returns whether or not a discount has been applied. | |
init ( ) | Loads the cart data from the PHP session during WordPress init and hooks in other methods. | |
is_empty ( ) : boolean | Checks if the cart is empty. | |
maybe_set_cart_cookies ( ) | Will set cart cookies if needed, once, during WP hook. | |
needs_payment ( ) : boolean | Looks at the totals to see if payment is actually required. | |
needs_shipping ( ) : boolean | Looks through the cart to see if shipping is actually required. | |
needs_shipping_address ( ) : boolean | Should the shipping address form be shown. | |
persistent_cart_destroy ( ) | Delete the persistent cart permanently. | |
persistent_cart_update ( ) | Save the persistent cart when the cart is updated. | |
remove_cart_item ( string $cart_item_key ) : boolean | Remove a cart item. | |
remove_coupon ( string $coupon_code ) : boolean | Remove a single coupon by code. | |
remove_coupons ( $deprecated = null ) | Remove coupons from the cart of a defined type. Type 1 is before tax, type 2 is after tax. | |
remove_taxes ( ) | Remove taxes. | |
restore_cart_item ( string $cart_item_key ) : boolean | Restore a cart item. | |
set_quantity ( string $cart_item_key, integer $quantity = 1, boolean $refresh_totals = true ) : boolean | Set the quantity for an item in the cart. | |
set_session ( ) | Sets the php session data for the cart and coupons. | |
ship_to_billing_address_only ( ) : boolean | Sees if we need a shipping address. | |
show_shipping ( ) : boolean | Sees if the customer has entered enough data to calc the shipping yet. |
Method | Description | |
---|---|---|
increase_coupon_applied_count ( string $code, integer $count = 1 ) | Store how many times each coupon is applied to cart/items. | |
increase_coupon_discount_amount ( string $code, double $amount, double $tax ) | Store how much discount each coupon grants. | |
reset ( boolean $unset_session = false ) | Reset cart totals to the defaults. Useful before running calculations. | |
set_cart_cookies ( boolean $set = true ) | Set cart hash cookie and items in cart. | |
sort_by_subtotal ( array $a, array $b ) : integer | Sort by subtotal. |
public __construct ( ) |
public add_discount ( string $coupon_code ) : boolean | ||
$coupon_code | string | - The code to apply |
return | boolean | True if the coupon is applied, false if it does not exist or cannot be applied |
public add_fee ( string $name, float $amount, boolean $taxable = false, string $tax_class = '' ) | ||
$name | string | Unique name for the fee. Multiple fees of the same name cannot be added. |
$amount | float | Fee amount. |
$taxable | boolean | (default: false) Is the fee taxable? |
$tax_class | string | (default: '') The tax class for the fee if taxable. A blank string is standard tax class. |
public add_to_cart ( integer $product_id, integer $quantity = 1, integer $variation_id, array $variation = [], array $cart_item_data = [] ) : string | boolean | ||
$product_id | integer | contains the id of the product to add to the cart |
$quantity | integer | contains the quantity of the item to add |
$variation_id | integer | |
$variation | array | attribute values |
$cart_item_data | array | extra cart item data we want to pass into the item |
return | string | boolean | $cart_item_key |
public apply_cart_discounts_after_tax ( $values, $price ) |
public apply_product_discounts_after_tax ( $values, $price ) |
public calculate_shipping ( ) |
public calculate_totals ( ) |
public check_cart_item_stock ( ) : boolean | WP_Error | ||
return | boolean | WP_Error |
public check_cart_item_validity ( ) : boolean | WP_Error | ||
return | boolean | WP_Error |
public check_customer_coupons ( array $posted ) | ||
$posted | array |
public coupons_enabled ( ) : boolean | ||
return | boolean |
public empty_cart ( boolean $clear_persistent_cart = true ) | ||
$clear_persistent_cart | boolean | (default: true) |
public find_product_in_cart ( $cart_id = false ) : string | ||
return | string | cart item key |
public generate_cart_id ( integer $product_id, integer $variation_id, array $variation = [], array $cart_item_data = [] ) : string | ||
$product_id | integer | - id of the product the key is being generated for |
$variation_id | integer | of the product the key is being generated for |
$variation | array | data for the cart item |
$cart_item_data | array | other cart item data passed which affects this items uniqueness in the cart |
return | string | cart item key |
public get_applied_coupons ( ) : array | ||
return | array | of applied coupons |
public get_cart_contents_count ( ) : integer | ||
return | integer |
public get_cart_contents_weight ( ) : integer | ||
return | integer |
public get_cart_discount_tax_total ( ) : float | ||
return | float |
public get_cart_discount_total ( ) : float | ||
return | float |
public get_cart_for_session ( ) : array | ||
return | array | contents of the cart |
public get_cart_from_session ( ) |
public get_cart_item ( string $item_key ) : array | ||
$item_key | string | Cart item key. |
return | array | Item data |
public get_cart_item_quantities ( ) : array | ||
return | array |
public get_cart_item_tax_classes ( ) : array | ||
return | array |
public get_cart_shipping_total ( ) : string | ||
return | string | price or string for the shipping total |
public get_cart_subtotal ( boolean $compound = false ) : string | ||
$compound | boolean | whether to include compound taxes |
return | string | formatted price |
public get_cart_tax ( ) : string | ||
return | string | formatted price |
public get_cart_total ( ) : string | ||
return | string | formatted price |
public get_cart_url ( ) : string | ||
return | string | url to page |
public get_checkout_url ( ) : string | ||
return | string | url to page |
public get_coupon_discount_tax_amount ( string $code ) : float | ||
$code | string | coupon code |
return | float | discount amount |
public get_coupons ( $deprecated = null ) : array | ||
return | array | of applied coupons |
public get_cross_sells ( ) : array | ||
return | array | cross_sells (item ids) |
public get_discounts_after_tax ( ) |
public get_discounts_before_tax ( ) : mixed | ||
return | mixed | formatted price or false if there are none |
public get_displayed_subtotal ( ) : string | ||
return | string |
public get_order_discount_total ( ) : integer | ||
return | integer |
public get_product_price ( WC_Product $product ) : string | ||
$product | WC_Product | |
return | string | formatted price |
public get_product_subtotal ( WC_Product $product, integer $quantity ) : string | ||
$product | WC_Product | |
$quantity | integer | |
return | string | formatted price |
public get_remove_url ( string $cart_item_key ) : string | ||
$cart_item_key | string | contains the id of the cart item |
return | string | url to page |
public get_shipping_packages ( ) : array | ||
return | array | of cart items |
public get_shipping_tax_amount ( string $tax_rate_id ) : float | ||
$tax_rate_id | string | |
return | float | amount |
public get_tax_amount ( string $tax_rate_id ) : float | ||
$tax_rate_id | string | |
return | float | amount |
public get_tax_totals ( ) : array | ||
return | array |
public get_total_discount ( ) : mixed | ||
return | mixed | formatted price or false if there are none |
public get_total_ex_tax ( ) : string | ||
return | string | formatted price |
public get_undo_url ( string $cart_item_key ) : string | ||
$cart_item_key | string | |
return | string | url to page |
public has_discount ( string $coupon_code = '' ) : boolean | ||
$coupon_code | string | |
return | boolean |
public init ( ) |
public maybe_set_cart_cookies ( ) |
public needs_payment ( ) : boolean | ||
return | boolean |
public needs_shipping ( ) : boolean | ||
return | boolean | whether or not the cart needs shipping |
public needs_shipping_address ( ) : boolean | ||
return | boolean |
public persistent_cart_destroy ( ) |
public persistent_cart_update ( ) |
public remove_cart_item ( string $cart_item_key ) : boolean | ||
$cart_item_key | string | |
return | boolean |
public remove_coupon ( string $coupon_code ) : boolean | ||
$coupon_code | string | Code of the coupon to remove |
return | boolean |
public remove_coupons ( $deprecated = null ) |
public restore_cart_item ( string $cart_item_key ) : boolean | ||
$cart_item_key | string | |
return | boolean |
public set_quantity ( string $cart_item_key, integer $quantity = 1, boolean $refresh_totals = true ) : boolean | ||
$cart_item_key | string | contains the id of the cart item |
$quantity | integer | contains the quantity of the item |
$refresh_totals | boolean | whether or not to calculate totals after setting the new qty |
return | boolean |
public set_session ( ) |
public ship_to_billing_address_only ( ) : boolean | ||
return | boolean |
public show_shipping ( ) : boolean | ||
return | boolean |
public $applied_coupons |
public $cart_contents_total |
public $cart_session_data |
public $coupon_applied_count |
public $coupon_discount_amounts |
public $coupon_discount_tax_amounts |
public $discount_cart_tax |
public $removed_cart_contents |
public $shipping_taxes |