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

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

BIABAJay
Shopify Partner
15 0 15

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 3 (3)

Nick_Wesselman
Shopify Staff
171 43 70

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
15 0 15

Been a while since I attempted this. 

is this something I could use?

 

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

harshad07
Shopify Partner
3 0 1