Shopify Function to add Buy one Get one

Hi all –

I am looking on an order level (I want to combine product level discounts) to replicate the functionality of an Automatic Discount in the Web UI:

So if a customer purchases two of an item they get another free (zero cost) and it automatically adds to cart.

So, can we in Shopify functions add a ProductVariant to cart, and change that item’s price to zero as is done through the Discount created in Shopify’s Admin panel above?

Why I want to do this: Our current production app uses the Shopify Script Editor, and Discounts to do two things:

A. In the script editor, discount for members (logged in) certain products.

B. In the Discounts Web UI, offer BOGO as above.

This works currently in production, however the Script editor is buggy, fails often, and is being deprecated.

I have a Shopify function in my Dev store that discounts that product fine. I understand discounts cannot be combined on the same products but I need that BOGO function because it DOES WORK WITH SCRIPT EDITOR.

So I want another function, order based, to count number of products in cart with certain tags, and add the lowest price one with price of zero based on the order. Is this possible?

[Discount Allocations won’t work, they as I understand it, are only available in Development Stores NOT production, and only serve to limit discounts to a max level. That is not what I want. I want BOGO combined with the discounted product, but not to add that discounted product as a zero dollar item which will have its own unique tag not shared by BOGO items.]

Really, really looking to get rid of the Shopify Script Editor script.

Thanks.

Hi @fwallace were you able to do this? I’m currently working on the same thing, and I was able to offer this product for free, but not to add it to the cart from the function

Nope, still working on this in spare moments