Capping Free Gifts with Shopify Flow: The Smart Way (Community-Backed Strategies)

Hey there, fellow store owners!

Running promotions is a fantastic way to boost sales, and offering a free gift with purchase is a classic. But what happens when you need to cap that promotion at a strict number, say 500 gifts, using Shopify Flow? This exact challenge recently sparked a great discussion in the Shopify Community, and the insights shared are gold for anyone looking to automate their offers reliably.

Capping Free Gifts with Shopify Flow: The Community's Best Advice

The conversation started with tatiaa, who wanted to use Shopify Flow to add a free gift to orders containing a specific product bundle, capped at exactly 500 orders. The natural first thought was to use a shop-level metafield as a counter: increment it each time a gift is added, and stop the flow once it hits 500. Sounds straightforward, right?

Not quite, as our community experts quickly pointed out. While a basic metafield counter can give you a rough idea, it's not foolproof for a truly exact cap, especially if your store sees a flurry of orders. This is where the notorious "race condition" rears its head.

The "Race Condition" Problem: Why Simple Counters Fall Short

Imagine two customers place qualifying orders almost simultaneously. Here's what could happen with a simple metafield counter:

  1. Order A triggers Flow. Flow reads the current counter (e.g., 499).
  2. Before Flow can update the counter, Order B triggers its own Flow instance.
  3. Flow for Order B also reads the counter (still 499!).
  4. Both orders add the free gift.
  5. Both orders then increment the counter, potentially pushing it to 501, or even higher if more orders come in during that tiny window.

As tim_1 and Gimmesales (Vineet from Identixweb) emphasized, this race condition means you could easily exceed your intended cap. For a strict limit, this just won't do.

So, what's the robust, battle-tested solution the community recommends?

The Smart & Reliable Way: Leveraging Product Inventory as Your Cap

This was the clear consensus from experts like liquidshop.co and Gimmesales. Instead of wrestling with complex counters, you tap into Shopify's rock-solid inventory management system. It's brilliantly simple and incredibly reliable!

The core idea is this: create a dedicated "free gift" product in your Shopify admin. Then, set its inventory to your exact cap (e.g., 500 units) and, critically, disable overselling. Your Shopify Flow then simply checks if this gift product is "in stock" before adding it to an order. Shopify's inventory system is built to handle concurrency flawlessly, meaning no race conditions to worry about here. Once 500 units are gone, Shopify's system prevents any further additions.

Step-by-Step: Setting Up the Inventory Method in Shopify Flow

This is the most straightforward and dependable path to a strict promotional cap. Here’s how you can implement it:

  1. Create Your Free Gift Product:

    • In your Shopify admin, go to Products > Add product.
    • Name it clearly (e.g., "Promo Free Gift - Limited 500").
    • Set its price to 0.00.
    • In the Inventory section:
      • Set "Quantity" to your desired cap (e.g., 500).
      • Crucial: Uncheck "Continue selling when out of stock." This prevents any additions once the inventory hits zero.
    • Ensure the product is active, but you might want to hide it from your online store so customers can't find it directly.
  2. Build Your Shopify Flow:

    • Navigate to your Shopify admin > Apps > Shopify Flow.
    • Click Create workflow.
    • Trigger: Use "Order created" (or "Order paid" for post-payment allocation).
    • Conditions:
      • Add a condition to identify qualifying orders (e.g., "Order Line items product title contains 'Your Bundle Product Name'").
      • Add the cap condition: "Product is in stock" for your "Promo Free Gift - Limited 500" product. This is how Flow respects your inventory cap.
    • Action:
      • Add the action "Add line item to order" or "Add free item to order."
      • Select your "Promo Free Gift - Limited 500" product.
      • Consider adding an "Add order tag" action (e.g., free-gift-added) for easy tracking.
    • Activate Your Workflow: Save and turn on your Flow.

Voila! Your promotion will now reliably stop at precisely 500 gifts, with Shopify's robust inventory system handling all the concurrency for you.

A Quick Look at the Metafield Counter Approach (and its Advanced Complexities)

While the inventory method is the clear winner for strict caps, let's briefly acknowledge the metafield counter idea for those who are curious or have less stringent needs. You can use a shop metafield and update it via Flow actions like "Update shop metafield" or "Send Admin API request."

Here's the basic JSON snippet for updating a metafield, as shared by Gimmesales:

{
"metafields": [
{
"ownerId": "{{ shop.id }}",
"namespace": "promotions",
"key": "free_gift_counter",
"type": "number_integer",
"value": "{{ shop.metafields.promotions.free_gift_counter.value | default: 0 | plus: 1 }}"
}
]
}

However, for true accuracy in a high-traffic scenario, you'd need advanced techniques like compareDigest with the metafieldsSet API call. This ensures the metafield hasn't changed between when you read it and when you try to update it. But, as tim_1 highlighted, Flow doesn't natively expose these values. Trying to implement this reliably often means delving into complex GraphQL queries, API tokens, and custom error handling – pushing it far beyond native Flow capabilities and often requiring a custom app.

So, while the direct counter concept is appealing, its reliable implementation for strict caps within Shopify Flow quickly becomes overly complex compared to the elegant simplicity of the inventory method.

When you need a strict, no-exceptions limit on your free gift promotions, the community's consensus is clear: leverage Shopify's robust inventory system. It's the most reliable, easiest to set up, and ensures your promotions run exactly as intended, every single time. Happy promoting!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases