Deletes the current site visitor's cart.
The deleteCurrentCart()
function returns a Promise that resolves when the current cart is deleted.
function deleteCurrentCart(): Promise<void>;
/**************************************
* Backend code - my-backend-file.web.js *
*************************************/
import { Permissions, webMethod } from "wix-web-module";
import { currentCart } from "wix-ecom-backend";
export const myDeleteCurrentCartFunction = webMethod(
Permissions.Anyone,
async () => {
try {
await currentCart.deleteCurrentCart();
console.log("Success! Deleted cart");
return;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/*************
* Page code *
************/
import { myDeleteCurrentCartFunction } from "backend/my-backend-file.web";
myDeleteCurrentCartFunction()
.then(() => {
console.log("Success! Deleted current 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.