Script Editor - Limiting product quantity script issue

Topic summary

Issue: A Shopify Script Editor line item script that limits product quantity (e.g., max 1) removes excess units but interferes with removal. When attempting to delete the item (decrement to 0 or trash icon), it briefly goes to 0, then returns to 1 with the message “You can only add 1 of this item to your cart.” A second removal attempt succeeds.

Repro (with Shopify’s example script):

  • Add item, increase to 2 → excess removed, quantity = 1, limit message shown.
  • Decrease to 0 or trash → quantity snaps back to 1, message persists.
  • Remove again → item finally removed.

Status: No confirmed fix; original poster accepted it as a bug. Another user reports similar behavior (item re-added after removal).

Proposed approach: A custom Ruby script using product tags (e.g., lqty:5) to set per-item limits. It uses instance_variable_set to cap quantity and adds a “Max Quantity Limit Reached” property. A code gist is attached and central to understanding the suggestion.

New request: Apply a single max quantity across variants/types (e.g., total of 7 stickers across colors). This cart-wide limit question remains unanswered.

Outcome: Unresolved; no definitive solution or decision yet.

Summarized with AI on January 23. AI used: gpt-5.

Hi @LucaHolland

Unfortunately, no. I just accepted there was a bug and so far there hasn’t really been customer issues with it.