How to add a free product for the first 100 customers using a unique discount code?

SuperJoel
Visitor
2 0 0

Hey everyone!! I'm looking to "ideally" create a shopify flow that adds a product to the first 100 customers who place an order using a unique discount code. 

 

This is ideal only as I would like to try and avoid using another app 😭 I've thought if setting the discount to only have 100 uses but we'd like for the promo to continue being used and only reward the first ones to use it. 

 

My current thought is somehow creating a counter in flow to keep track of it but then the logic seems to become unmanageable. Does anyone have any ideas or thoughts on how to tackle this? I'm still open to an app if that's my only option lol

Replies 3 (3)

paul_n
Shopify Staff
1010 133 240

It's not clear exactly what you are doing now and what you are looking to change. Can you elaborate a bit more?

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
SuperJoel
Visitor
2 0 0
Hi Paul! Thanks for replying - What I'm looking to do is create a discount
code that would have a dual purpose. The first 100 customers to place an
order using the promo code are rewarded with an additional product along
with a discount on their order. After the first 100 uses, the discount code
would remain active but no longer reward the additional product.
paul_n
Shopify Staff
1010 133 240

Looking at the API, there isn't an easy way to do it because the number of uses isn't available via the order.  The order does carry the discount code as a string, but it doesn't know how often it was used. You could possibly count every use of a discount by using a metafield. Something like:

- Order created
- if order.discountCode == "XYZ":
- if shop / metafields / discount_code_use < 100:
   - Add order line item
   - Update shop metafield (increment by 1)

The downside of this is that you might occasionally go over 100 if two orders came in at the same time. Also it wouldn't reflect the current uses of an existing discount code.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.