Deletes a cart.
The deleteCart()
function returns a Promise that resolves when the specified cart is deleted.
function deleteCart(_id: string): Promise<void>;
ID of the cart to delete.
/**************************************
* Backend code - my-backend-file.web.js *
*************************************/
import { Permissions, webMethod } from "wix-web-module";
import { cart } from "wix-ecom-backend";
export const myDeleteCartFunction = webMethod(
Permissions.Anyone,
async (cartId) => {
try {
await cart.deleteCart(cartId);
console.log("Success! Deleted cart");
return;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/*************
* Page code *
************/
import { myDeleteCartFunction } from "backend/my-backend-file.web";
// Sample cartId:
const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd";
myDeleteCartFunction(cartId)
.then(() => {
console.log("Success! Deleted cart");
return;
})
.catch((error) => {
console.error(error);
// Handle the error
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.