Cart::add_to_cart( int $product_id, int $quantity = 1, int $variation_id, array $variation = array(), array $cart_item_data = array() )
Based on the core cart class but returns errors rather than rendering notices directly.
Description Description
Parameters Parameters
- $product_id
-
(Required) contains the id of the product to add to the cart.
- $quantity
-
(Optional) contains the quantity of the item to add.
Default value: 1
- $variation_id
-
(Required) ID of the variation being added to the cart.
- $variation
-
(Optional) attribute values.
Default value: array()
- $cart_item_data
-
(Optional) extra cart item data we want to pass into the item.
Default value: array()
Return Return
(string|WP_Error)
Source Source
File: woocommerce/packages/woocommerce-blocks/src/RestApi/Controllers/Cart.php