CartController
Woo Cart Controller class.
Description Description
Helper class to bridge the gap between the cart API and Woo core.
Source Source
File: packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php
Changelog Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |
Methods Methods
- add_product_names_to_message — Generates the error message for out of stock products and adds product names to it.
- add_to_cart — Based on the core cart class but returns errors rather than rendering notices directly.
- apply_coupon — Based on the core cart class but returns errors rather than rendering notices directly.
- empty_cart — Empty cart contents.
- filter_request_data — Filter data for add to cart requests.
- get_cart_coupon_errors — Validate all items in the cart and get a list of errors.
- get_cart_coupons — Returns all applied coupons.
- get_cart_hashes — Get hashes for items in the current cart. Useful for tracking changes.
- get_cart_instance — Get main instance of cart class.
- get_cart_item — Return a cart item from the woo core cart class.
- get_cart_item_errors — Validate all items in the cart and get a list of errors.
- get_cart_items — Returns all cart items.
- get_error_message_for_stock_exception_type — Takes a string describing the type of stock extension, whether there is a single product or multiple products causing this exception and returns an appropriate error message.
- get_package_name — Creates a name for a package.
- get_product_for_cart — Get a product object to be added to the cart.
- get_product_id — For a given product, get the product ID.
- get_product_quantity_in_cart — Gets the qty of a product across line items.
- get_remaining_stock_for_product — Gets remaining stock for a product.
- get_shipping_packages — Get shipping packages from the cart with calculated shipping rates.
- get_variable_product_attributes — Get product attributes from the variable product (which may be the parent if the product object is a variation).
- get_variation_id — For a given product, get the variation ID.
- get_variation_id_from_variation_data — Try to match request data to a variation ID and return the ID.
- has_coupon — See if cart has applied coupon by code.
- load_cart — Makes the cart and sessions available to a route by loading them from core.
- parse_variation_data — If variations are set, validate and format the values ready to add to the cart.
- sanitize_variation_data — Format and sanitize variation data posted to the API.
- select_shipping_rate — Selects a shipping rate.
- set_cart_item_quantity — Based on core `set_quantity` method, but validates if an item is sold individually first.
- stock_exceptions_to_wp_errors — This method will take arrays of exceptions relating to stock, and will convert them to a WP_Error object.
- throw_default_product_exception — Default exception thrown when an item cannot be added to the cart.
- validate_add_to_cart — Validate all items in the cart and check for errors.
- validate_cart_coupon — Validates an existing cart coupon and returns any errors.
- validate_cart_coupons — Validate all coupons in the cart and check for errors.
- validate_cart_item — Validates an existing cart item and returns any errors.
- validate_cart_items — Validate all items in the cart and check for errors.