Skip to main content
openbridge.cart.remove(lineId)
openbridge.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 = openbridge.cart.lines()
await openbridge.cart.remove(lines[0].id)

Remove multiple items

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

await openbridge.cart.remove(idsToRemove)

Remove button

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

Remove all of a specific product

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

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

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