How to automatically remove a line item when conditions are no longer met?

Hi,

We’re running a standard “Spend $X, get a free gift” promotion and have hit a roadblock with Cart Transform that’s forcing a poor customer experience.

What works today

  • Customer hits $100 → adds free gift (marked with a line attribute)

  • Discount Function applies 100% off the gift → perfect

The problem

When the customer removes items and the cart drops below $100, the free gift is no longer eligible and should disappear from the cart automatically.

Current Cart Transform operations available

  • lineExpand

  • lineUpdate (price/title/image – Plus only)

  • linesMerge

None of these let us remove a line item or set its quantity to 0.

Current workaround

We’re using Cart Validation to block checkout with an error (“Please remove the free gift, your cart no longer qualifies”), which forces the customer to manually delete the gift themselves → really bad UX.

Question to the community / Shopify

Is there any way with the current Cart Transform API (or any other Function type) to programmatically remove a cart line or set its quantity to 0 when a condition is no longer met?

Just trying to avoid forcing customers to manually clean up their cart.

cartLineChange accepts a CartLineRemoveChange object which allows you to remove the line or specific quantities.

As an example:

const childOptions = {
	id: addonLine.id,
	quantity: addonLine.quantity,
	type: "removeCartLine",
}
const { applyCartLinesChange } = shopify;
const childResult = await applyCartLinesChange(childOptions);

@ceri_waters that looks like a workaround using checkout UI, not with a function.