Why is there no route that allows an array of products to be added to the cart? #9775
-
Hi all, I was looking at the Store API docs, and it seems like (or at least to me it does), that the I've also traced it back here: This confused me at first because the route path implies you can add multiple items. Maybe I'm missing something? If not, I would love to know what the preferred way is of adding say, 10 items to the cart. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @multiplehats - please take a look at this document Specifically the "Batching" section of the Add Item route. You can add multiple items by making a batch request containing multiple The JSON payload for adding multiple items would look like this: {
"requests": [
{
"path": "/wc/store/v1/cart/add-item",
"method": "POST",
"cache": "no-store",
"body": {
"id": 26,
"quantity": 1
},
"headers": {
"Nonce": "1db1d13784"
}
},
{
"path": "/wc/store/v1/cart/add-item",
"method": "POST",
"cache": "no-store",
"body": {
"id": 27,
"quantity": 1
},
"headers": {
"Nonce": "1db1d13784"
}
}
]
} I'll close this discussion since it has a definitive answer, but please feel free to reopen it if you would like to discuss further! |
Beta Was this translation helpful? Give feedback.
Hi @multiplehats - please take a look at this document
https://github.com/woocommerce/woocommerce-blocks/blob/trunk/src/StoreApi/docs/cart.md#add-item
Specifically the "Batching" section of the Add Item route.
You can add multiple items by making a batch request containing multiple
cart/add-item
requests.The JSON payload for adding multiple items would look like this: