Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

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

BIABAJay
Shopify Partner
11 0 12

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?

Replies 2 (2)

Nick_Wesselman
Shopify Staff
117 29 45

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

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

BIABAJay
Shopify Partner
11 0 12

Been a while since I attempted this. 

is this something I could use?

 

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