Cart_Handler
in package
implements
Service, Registerable, Conditional
This class handles caching for the product tables.
Tags
Interfaces, Classes and Traits
- Service
- Marker interface to denote a service.
- Registerable
- An object that can be registered with WordPress via the Plugin API, i.e. add_action() and add_filter().
- Conditional
- An object which is loaded conditionally.
Table of Contents
- add_to_cart() : mixed
- add_to_cart_multi() : array<string|int, mixed>
- Add multiple products to the cart in a single step.
- get_multi_cart_data() : array<string|int, mixed>
- Get the posted multi cart data as an array, with the correct integer product IDs.
- is_required() : bool
- Is this object required?
- process_multi_cart() : mixed
- product_addons_cart_item_data_wrapper() : mixed
- product_addons_validate_cart_item() : mixed
- register() : mixed
- fix_cart_data_product_ids() : array<string|int, mixed>
- Posted cart_data uses indexes of the form 'p1234' where '1234' is the product ID.
- product_addons_add_cart_item_data() : mixed
Methods
add_to_cart()
public
static add_to_cart(mixed $product_id[, mixed $quantity = 1 ][, mixed $variation_id = false ][, mixed $variations = false ]) : mixed
Parameters
- $product_id : mixed
- $quantity : mixed = 1
- $variation_id : mixed = false
- $variations : mixed = false
Return values
mixed —add_to_cart_multi()
Add multiple products to the cart in a single step.
public
static add_to_cart_multi(type $products) : array<string|int, mixed>
Parameters
- $products : type
-
- An array of products (including quantities and variation data) to add to the cart
Return values
array<string|int, mixed> —An array of product IDs => quantity added
get_multi_cart_data()
Get the posted multi cart data as an array, with the correct integer product IDs.
public
static get_multi_cart_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —The multi cart data (product IDs => product data)
is_required()
Is this object required?
public
is_required() : bool
Return values
bool —true if required, false otherwise.
process_multi_cart()
public
process_multi_cart() : mixed
Return values
mixed —product_addons_cart_item_data_wrapper()
public
static product_addons_cart_item_data_wrapper(mixed $cart_item_data, mixed $product_id) : mixed
Parameters
- $cart_item_data : mixed
- $product_id : mixed
Return values
mixed —product_addons_validate_cart_item()
public
static product_addons_validate_cart_item(mixed $passed, mixed $product_id, mixed $qty) : mixed
Parameters
- $passed : mixed
- $product_id : mixed
- $qty : mixed
Return values
mixed —register()
public
register() : mixed
Return values
mixed —fix_cart_data_product_ids()
Posted cart_data uses indexes of the form 'p1234' where '1234' is the product ID.
private
static fix_cart_data_product_ids(array<string|int, mixed> $cart_data) : array<string|int, mixed>
This is because of a limitation of the JS serializeObject function. We run this function to remove the 'p' prefix from each index in the array.
Parameters
- $cart_data : array<string|int, mixed>
-
The cart data to be sanitized
Return values
array<string|int, mixed> —The same array with keys replaced with the corresponding product ID
product_addons_add_cart_item_data()
private
static product_addons_add_cart_item_data(mixed $cart_item_data, mixed $product_id, mixed $post_data) : mixed
Parameters
- $cart_item_data : mixed
- $product_id : mixed
- $post_data : mixed