Function to Add/Remove Products From Cart

I’d like to do as the title says in a function as opposed to using the Ajax api. We have charges for personalization that need to be added if an item is personalized and removed if the order is over $200. The Ajax api has worked up until now but this is really server side logic. Also the Ajax api isn’t perfect and charges are missed occasionally. The function would need access to the current cart and a failsafe for infinite looping which the time limits may already do.

HI Timothy,

With a function like this, would the customer be able to opt-in to having a product added to their cart? I’m just cautious that this kind of a function could be misused to add products to an order without customer consent, see this rule in the app store requirements:

Apps can’t automatically add or pre-select optional charges to a buyer’s cart that increase the total checkout price. Apps can only add optional charges to carts or at checkout after displaying the additional cost in a manner that is clear to the buyer, and upon obtaining explicit buyer consent.

In our business model, certain product customizations—like personalization or oversized shipping—carry additional charges that are clearly communicated on the product page and reflected as separate line items in the cart. Consent is transparently captured when the customer adds the item to the cart, ensuring clarity and in pricing.

Currently, Shopify’s client-side scripting is the only reliable way to automate these cart adjustments, but it comes with significant limitations. Scripts may fail to execute properly due to connection issues, browser restrictions, or fast user navigation—especially when users move quickly from the cart to checkout. This unreliability results in thousands of dollars in lost revenue annually for us, as mandatory add-ons are occasionally skipped.

While concerns about potential abuse of product injection are valid, they’re largely mitigated by the nature of the Shopify platform:

  • The checkout is secure and locked down.
  • Products cannot be hidden from the customer.
  • Malicious intent is self-defeating—any app or merchant using this feature deceptively would quickly lose trust and customers.
  • Existing capabilities (like product variants and pricing manipulation) already provide means for abuse; this feature wouldn’t introduce new risks but rather offer more dependable tools to honest merchants.

For merchants like us, this change would unlock more robust, scalable, and error-resistant cart behaviors. It would also open up adoption of newer UI patterns like popover carts, which we currently avoid due to the fragility of client-side scripting.

Thank you for considering this enhancement. We believe it has strong potential to improve merchant experience without compromising customer trust, and we hope it gains support.

Thanks for describing your use-case Timothy - I’ve raised this as a feature request to our team.

Thank You. I appreciate it.