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

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 :sob: 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

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

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.

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.