Deletes a cart in a webstore.
Syntax
import { deleteCart } from 'lightning/commerceCartApi';
deleteCart(cartInput: object): Promise<void>
Commerce API Resource
DELETE /commerce/webstores/{webstoreId}/carts/{activeCartOrId}
deleteCart uses this Commerce API resource.
Parameters
webstoreId—(Required) The ID of the webstore. The ID prefix is0ZE.activeCartOrId—(Required) The ID of the cart to delete, or the stringactiveto target the buyer's active cart.version—(Required) The API version for the adapter, for example,v62.0. Without this parameter, the call doesn't fire.effectiveAccountId—(Optional) The effective account ID for the cart operation.
Returns
The return type is void. On success, the server returns 204 No Content. On error, the Promise rejects with an error object containing an errorCode and a message.
Usage
deleteCart is an imperative function, not a @wire adapter. Call it in response to a user action.
import { LightningElement, api } from 'lwc';
import { deleteCart } from 'lightning/commerceCartApi';
export default class DeleteCartExample extends LightningElement {
@api webstoreId;
@api cartId;
async handleDeleteCart() {
try {
await deleteCart({
webstoreId: this.webstoreId,
activeCartOrId: this.cartId,
version: 'v62.0',
});
console.log('Cart deleted successfully');
} catch (error) {
console.error('Error deleting cart:', error);
}
}
}
Error Handling
If the call fails, the Promise rejects with an error object containing an errorCode and a message.
See Also