Is it possible to add items to the cart via Shopify Functions?

I need to add “Recycling Fees” to the cart for 3 states. Currently I edited checkout.liquid to check the state and then add a recycling fee product to the cart. It looks like Shopify will be removing our ability to edit checkout.liquid. I need to find another way to accomplish this. Would Shopify Functions be the answer?

Hi @BIABAJay – There is no way to do this with Functions currently. We’d recommend using a Checkout UI extension for this. Not my area of expertise but the following may help you get started.

https://shopify.dev/docs/apps/checkout/product-offers/pre-purchase/getting-started

https://shopify.dev/docs/api/checkout-ui-extensions/react-hooks/cart/useapplycartlineschange

Been a while since I attempted this.

is this something I could use?

https://shopify.dev/docs/api/functions/reference/cart-transform

In the Checkout UI extension API calls are not properly working

https://community.shopify.com/c/extensions/could-not-apply-line-item-changes-when-we-use-applycartlines/td-p/2464382