Skip to main content
shoppy.cart.remove(lineId)
shoppy.cart.remove(lineIds)
Removes one or more items from the cart.

Parameters

Single item

ParamTypeRequiredDescription
lineIdstringYesCart line ID

Multiple items

ParamTypeRequiredDescription
lineIdsstring[]YesArray of line IDs

Returns

Promise<ShopifyCart>

Examples

Remove single item

const lines = shoppy.cart.lines()
await shoppy.cart.remove(lines[0].id)

Remove multiple items

const lines = shoppy.cart.lines()
const idsToRemove = lines.slice(0, 2).map((l) => l.id)

await shoppy.cart.remove(idsToRemove)

Remove button

document.querySelectorAll('.remove-item').forEach((button) => {
    button.addEventListener('click', async () => {
        const lineId = button.dataset.lineId
        await shoppy.cart.remove(lineId)
    })
})

Remove all of a specific product

const productHandle = 'awesome-tshirt'
const lines = shoppy.cart.lines()

const linesToRemove = lines
    .filter((line) => line.merchandise.product.handle === productHandle)
    .map((line) => line.id)

if (linesToRemove.length > 0) {
    await shoppy.cart.remove(linesToRemove)
}
To remove all items at once, use .clear() instead.