Cart_Processor
Interface for classes that handle the processing of bundle products during a standard WooCommerce add-to-cart form submission.
Table of Contents
- filter_item_cart_data() : array<string|int, mixed>
- Adds custom data to a cart item when it's being added as part of a volume bundle.
- process_add_to_cart_form() : array<string|int, mixed>|bool
- Handles the form submission for adding a bundle to the cart.
Methods
filter_item_cart_data()
Adds custom data to a cart item when it's being added as part of a volume bundle.
public
filter_item_cart_data(array<string|int, mixed> $cart_item_data, int $product_id_being_added, int $variation_id_being_added, int $quantity_being_added) : array<string|int, mixed>
This method is intended to be hooked to the 'woocommerce_add_cart_item_data' filter.
Parameters
- $cart_item_data : array<string|int, mixed>
-
Existing cart item data.
- $product_id_being_added : int
-
The product ID currently being added to the cart.
- $variation_id_being_added : int
-
The variation ID, if applicable.
- $quantity_being_added : int
-
The quantity of this specific item being added.
Return values
array<string|int, mixed> —Modified cart item data with bundle-specific information.
process_add_to_cart_form()
Handles the form submission for adding a bundle to the cart.
public
process_add_to_cart_form(int $product_id) : array<string|int, mixed>|bool
This method is responsible for:
- Validating submitted POST data (nonce, product ID, selected bundle, item variations).
- Retrieving the specific bundle configuration.
- Looping through the quantity specified in the bundle.
- For each item, calling WC()->cart->add_to_cart() with appropriate parameters.
- Setting success/error notices.
- Potentially redirecting the user (e.g., to the cart page).
Parameters
- $product_id : int
-
The ID of the main product being added.
Return values
array<string|int, mixed>|bool —Array of successfully added item names on success, false otherwise. The method itself usually handles redirection or notice display.