Checkout Extensibility + Auto Add Free Gift Product

Checkout Extensibility + Auto Add Free Gift Product

jains
Shopify Partner
12 0 8

We are trying to find a new solution to migrate from checkout.liquid to extensibility.

There is one big issue that is preventing the migration.

We would like to add a free gift with purchase (GWP) when a customer enters a specific discount code.

 

Existing implementation on checkout.liquid

  • Create discount code in Shopify admin. Buy Y get X free.
  • On checkout.liquid we store a Javascript object which has a list of all the discount codes associated with GWPs.
  • Customer enters discount code in checkout.
  • We listen to the page:load page:change Javascript event for discount code input.
  • We check the Javascript object to see if there is a GWP associated with the discount code and whether the cart meets the minimum requirements.
  • If requirements are met then we post the GWP variant ID to the cart/add.js endpoint and refresh the page.
  • Item is in the cart and discounted to £0/$0.

Checkout extensibility issue

In checkout extensibility there is no way to listen to the discount code input (if requirements not met) via a Checkout UI block.

Here is the problem: 

  1. Customer enters discount code
  2. Discount code is technically invalid because product Y is not in the cart (it needs to be added at this point due to code being input) no discount is applied
  3. Because no discount is applied the code does not appear in the useDiscountCodes array so we do not know to add the product

If we had a way to retrieve the discount code input regardless of validity we could then do the logic and validity checks ourselves and add the variant to the cart if requirements are met.

Have also spoke to a couple of discount app developers who have migrated to functions and they are also up against the same challenge.
We are looking for a way to achieve this as soon as possible.

Replies 4 (4)

RMedia
Shopify Partner
117 10 15

@jains did you find a solution to this yet?

Founder @ Advanced Free Shipping, create custom free shipping rules easily.
- Set Free-Shipping by 20 parameters; products, collections, customers + more
- No need for confusing Scripts or Carrier Calculated Shipping
- To learn more about 'Advanced Free Shipping' visit our Shopify app page here.
jains
Shopify Partner
12 0 8

Nope. Shopify don't seem interested either.

The only way I can think of is the following:

Order level discount with £0 value which is the code the customer needs to add.

Checkout extension listens for order code being added and does two things:

  • Adds the free product/gift with purchase
  • Adds a cart attribute
  • A product function which discounts said gift IF the cart attribute exists

 

What a mess!!!

RMedia
Shopify Partner
117 10 15

Yes, thats the only solution/scenario I seemed to come up with also... nice to know Im not missing something here.  Appreciate the reply.  Thanks

Founder @ Advanced Free Shipping, create custom free shipping rules easily.
- Set Free-Shipping by 20 parameters; products, collections, customers + more
- No need for confusing Scripts or Carrier Calculated Shipping
- To learn more about 'Advanced Free Shipping' visit our Shopify app page here.

robincingh
Shopify Partner
8 0 0