Skip to content

Instantly share code, notes, and snippets.

@petercossey
Created July 5, 2022 04:22
Show Gist options
  • Save petercossey/669aaa7a25c99d6d8e4c889c32c863a8 to your computer and use it in GitHub Desktop.
Save petercossey/669aaa7a25c99d6d8e4c889c32c863a8 to your computer and use it in GitHub Desktop.
Script you can execute on a BigCommerce Stencil storefront to delete existing cart for current session.
const myStorefrontUrl = "http://my-storefront.com"
findAndDeleteCart(myStorefrontUrl);
function findAndDeleteCart(storefrontUrl) {
fetch(storefrontUrl + "/api/storefront/carts", {
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(cart => {
if (cart.length < 1) return;
return fetch(storefrontUrl + "/api/storefront/carts/" + cart[0].id ,{
"method": "DELETE",
"headers": {
"Content-Type": "application/json"
}
});
})
.then(response => console.log(response))
.catch(err => console.log(err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment