Search.../

deleteCart( )

Deletes a cart.

Description

The deleteCart() function returns a Promise that resolves when the specified cart is deleted.

Syntax

function deleteCart(_id: string): Promise<void>

deleteCart Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the cart to delete.

Returns

Fulfilled - When the cart is deleted. Rejected - Error message.

Return Type:

Promise<
void
>

Was this helpful?

Delete a cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { cart } from 'wix-ecom-backend';
7
8export const myDeleteCartFunction = webMethod(Permissions.Anyone, async (cartId) => {
9 try {
10 await cart.deleteCart(cartId);
11 console.log('Success! Deleted cart');
12 return;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myDeleteCartFunction } from 'backend/my-backend-file.web';
24
25// Sample cartId:
26const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';
27
28myDeleteCartFunction(cartId)
29 .then(() => {
30 console.log('Success! Deleted cart');
31 return;
32 })
33 .catch((error) => {
34 console.error(error);
35 // Handle the error
36 });