Class WC_Cart
WooCommerce cart
The WooCommerce cart class stores cart data and active coupons as well as handling customer sessions and some cart related urls. The cart class also has a price calculation function which calls upon other classes to calculate totals.
Category: Class
Author: WooThemes
Version: 2.1.0
Class: WC_Cart
Located at includes/class-wc-cart.php
Methods summary
public
|
|
public
|
|
public
|
|
public
|
|
public
|
#
empty_cart( boolean $clear_persistent_cart = true )
Empties the cart and optionally the persistent cart too. |
public
|
|
public
|
|
public
boolean
|
|
public
integer
|
|
public
|
|
public
|
|
public
array
|
#
get_cart_item_quantities( )
Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines. |
public
boolean|WP_Error
|
#
check_cart_item_validity( )
Looks through cart items and checks the posts are not trashed or deleted. |
public
boolean|WP_Error
|
#
check_cart_item_stock( )
Looks through the cart to check each item is in stock. If not, add an error. |
public
string
|
#
get_item_data( array $cart_item, boolean $flat = false )
Gets and formats a list of cart item data + variations for display on the frontend. |
public
array
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
array
|
|
public
array
|
|
public
array
|
|
public
string
|
#
find_product_in_cart( mixed $cart_id = false )
Check if product is in the cart and return cart item key. |
public
string
|
#
generate_cart_id( integer $product_id, integer $variation_id = 0, array $variation = array(), array $cart_item_data = array() )
Generate a unique ID for the cart item being added. |
public
boolean
|
#
add_to_cart( string $product_id, string $quantity = 1, integer $variation_id = '', array $variation = '', array $cart_item_data = array() )
Add a product to the cart. |
public
|
#
set_quantity( string $cart_item_key, string $quantity = 1, boolean $refresh_totals = true )
Set the quantity for an item in the cart. |
public
|
|
public
|
|
public
boolean
|
|
public
|
#
calculate_shipping( )
Uses the shipping class to calculate shipping then gets the totals when its finished. |
public
array
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
string
|
|
public
|
#
check_customer_coupons( array $posted )
Check for user coupons (now that we have billing email). If a coupon is invalid, add an error. |
public
boolean
|
|
public
boolean
|
|
public
array
|
|
public
array
|
|
public
|
#
remove_coupons( mixed $type = null )
Remove coupons from the cart of a defined type. Type 1 is before tax, type 2 is after tax. |
public
boolean
|
|
public
float
|
#
get_discounted_price( mixed $values, mixed $price, boolean $add_totals = false )
Function to apply discounts to a product and get the discounted price (before tax is applied). |
public
|
|
public
|
#
apply_product_discounts_after_tax( mixed $values, mixed $price )
Function to apply product discounts after tax. |
public
|
|
public
array
|
|
public
|
|
public
float
|
|
public
float
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
float
|
#
get_taxes_total( boolean $compound = true, boolean $display = true )
Get tax row amounts with or without compound taxes includes. |
public
mixed
|
#
get_discounts_before_tax( )
Gets the total (product) discount amount - these are applied before tax. |
public
mixed
|
|
public
mixed
|
Magic methods summary
Properties summary
public
array
|
$cart_contents |
#
Contains an array of cart items. |
public
array
|
$applied_coupons |
#
Contains an array of coupon codes applied to the cart. |
public
array
|
$coupon_discount_amounts |
#
Contains an array of coupon code discounts after they have been applied. |
public
array
|
$coupon_applied_count |
#
Contains an array of coupon usage counts after they have been applied. |
public
float
|
$cart_contents_total |
#
The total cost of the cart items. |
public
float
|
$cart_contents_weight |
#
The total weight of the cart items. |
public
float
|
$cart_contents_count |
#
The total count of the cart items. |
public
float
|
$cart_contents_tax |
#
The total tax for the cart items. |
public
float
|
$total |
#
Cart grand total. |
public
float
|
$subtotal |
#
Cart subtotal. |
public
float
|
$subtotal_ex_tax |
#
Cart subtotal without tax. |
public
float
|
$tax_total |
#
Total cart tax. |
public
array
|
$taxes |
#
An array of taxes/tax rates for the cart. |
public
array
|
$shipping_taxes |
#
An array of taxes/tax rates for the shipping. |
public
float
|
$discount_cart |
#
Discounts before tax. |
public
float
|
$discount_total |
#
Discounts after tax. |
public
float
|
$fee_total |
#
Total for additional fees. |
public
float
|
$shipping_total |
#
Shipping cost. |
public
float
|
$shipping_tax_total |
#
Shipping tax. |
public
|
$tax | |
public
array
|
$cart_session_data |
#
cart_session_data |
public
array
|
$fees |
#
An array of fees. |