How to create a disposable discount(automatic/code) for specific customer(or groups)?

Now we have Buy X Get Y / Order Discount / Product Discount.

But All of them can be used infinitely until deleted / cancelled.

I want to create a discount code that can only be applied once, then it’s deleted/ cancelled.
Any solution?

1 Like

Hey @Polarove, you can limit discount codes to specific customers or groups and restrict usage per customer using the discountCodeBasicCreate mutation. The key fields are:

  • context - Target specific customer segments or individual customers
  • appliesOncePerCustomer: true - Limits the code to one use per customer (tracked by email/phone)
  • usageLimit - Sets total uses across all customers

Here’s an example targeting a customer segment:

mutation CreateSegmentDiscount($basicCodeDiscount: DiscountCodeBasicInput!) {
  discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
    codeDiscountNode {
      id
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "basicCodeDiscount": {
    "title": "One-Time Discount",
    "code": "ONETIME10",
    "context": {
      "customerSegments": {
        "add": ["gid://shopify/Segment/YOUR_SEGMENT_ID"]
      }
    },
    "customerGets": {
      "value": {
        "percentage": 0.10
      },
      "items": {
        "all": true
      }
    },
    "appliesOncePerCustomer": true
  }
}

For context, automatic deletion after use isn’t currently supported. The code remains in your admin after reaching usage limits (though it becomes inactive). Can you share more about your use case for needing automatic deletion? For example, are you trying to prevent code reuse, manage admin clutter, or implement a specific workflow? This would help me submit a more detailed feature request if needed.

Relevant docs:

Hey @Polarove, did the above help at all?

1 Like