Remove item I just added

Is there a way I can create a button that removes a product that i just added to the cart?

untested but it should point you in the right direction:

let cartItems =;
if (cartItems.length > 0) {
    let lastItem = cartItems.slice(-1)[0];


Hi there,

@azicchetti ’ solution is using the right API method for your need. You basically need the unique ID of the item you want to remove and pass it to the remove method. You can find more information about this method in our documentation : JavaScript SDK API – Snipcart Documentation

Hope this helps!

Hi that’s not quite what i meant.

I’m looking to have the function that once a product is added, a ‘remove’ button then appears. So if you click the ‘remove’ button, it will remove that specific product, not just the most recently added

@dominic @azicchetti Any ideas on my last comment?

Currently got this, but doesn’t work. I have multiple products on 1 page so struggling to get each of their unique Id’s

methods: {
    remove: function () {

Hi there,

You might have luck with something like this:'item.added', (cartItem) => {
    let uniqueId = cartItem.uniqueId;
    let itemId =;
    let addToCartButton = FindItemButtonInHtmlPageWithItemId(itemId)

   let deleteBtn = document.createElement("button");
   btn.innerHTML = "Delete the product";
   btn.onclick = function () {