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()


Top ↑

Return Return

(string|WP_Error)


Top ↑

Source Source

File: woocommerce/packages/woocommerce-blocks/src/RestApi/Controllers/Cart.php


			

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.