Customer tag based automatic discount

Customer tag based automatic discount

irfan3
Shopify Partner
9 0 2

Hi,

 

Is it possible to create the customer's tag-based automatic discount using the automatic discount API: https://shopify.dev/apps/discounts/automatic

 

e.g: I want to offer a 10% discount to all customers who has ABDC tag.

 

Any help and clue to achieve similar either using the above API or using any custom approach are really appreciated.

 

Thanks

Replies 11 (11)

NiccosMedia
Shopify Partner
51 4 14

Based on the information provided in the Shopify developer documentation, it is possible to create a customer tag-based automatic discount using the Automatic Discounts API. This API allows you to create discounts that are automatically applied to orders based on certain conditions, such as the customer's tags or the items in their cart.

To create a customer tag-based automatic discount, you would need to use the POST /admin/discounts.json endpoint to create a new discount, and specify the customer_tag condition in the prerequisite_customer_tags property of the discount. For example, the following code creates a discount that offers a 10% discount to all customers who have the ABDC tag:

 

POST /admin/discounts.json

{
"discount": {
"title": "10% off for customers with the ABDC tag",
"target_type": "line_item",
"target_selection": "all",
"allocation_method": "percentage",
"value": "10.0",
"prerequisite_customer_tags": [
"ABDC"
]
}
}

 

Once you have created the discount, it will be automatically applied to orders that meet the specified conditions, in this case orders placed by customers who have the ABDC tag.

Greetings Niclas
Senior Front-End Developer
Founder of Niccos Media
Based in Germany
kontakt@niccos-media.de
irfan3
Shopify Partner
9 0 2

@NiccosMedia - can you please share the API reference link for the above?

 

I checked but did not get any REST API available for such an automatic discount.

 

 

 

EcomGraduates
Shopify Partner
735 63 105

Hello there  

Yes, it is possible to create a customer tag-based automatic discount using Shopify's automatic discount feature. Here's how you can do it:

  1. In your Shopify admin, go to Discounts and click on the "Create automatic discount" button.
  2. Select "Customer tag" as the discount type and choose the tag that you want to apply the discount to. You can also set the discount to apply to all customers with the tag, or only to specific customers.
  3. Set the discount amount and choose whether it will be a percentage or a fixed amount.
  4. Set the start and end dates for the discount, or choose to make it ongoing.
  5. Click "Save" to create the discount.

 

Once you've created the discount, it will automatically be applied to orders placed by customers with the specified tag. It's important to note that automatic discounts will only apply to eligible products and will not stack with other discounts or promotions.

You can also use Shopify's automatic discount feature to create discounts based on other criteria, such as the customer's location, the amount of the order, or the shipping rate. It's a useful tool for creating targeted promotions and offering special discounts to specific groups of customers.

 


If this fixed your issue, likes and accepting as a solution are highly appreciated.

Build an online presence with our custom built Shopify Theme EcomifyTheme




irfan3
Shopify Partner
9 0 2

Hi,

 

Are you sure, the customer tag or segment option comes with an Automatic discount?

 

As checked,

 

It is not coming with an Automatic discount option: https://prnt.sc/wHX09aa-S2TV

It is coming only with a Normal discount: https://prnt.sc/zvp0oLrpX-Dy

 

Can you share a screenshot of what you are suggesting?

 

Thank you!

 

tobebuilds
Shopify Partner
457 32 120

Hey Irfan,

 

You're correct, there's no way to limit automatic discounts to customer tags in Shopify's built-in discounts.

 

I answered this question in another thread:

 

https://community.shopify.com/c/shopify-discussions/apply-automatic-discount-to-tagged-customers/m-p...

 

But TLDR, you have 2 options at this point:

  1. Use Shopify Functions to create your own discount manually. Here is the documentation: https://shopify.dev/docs/apps/functions
  2. Use an app, like Regios Automatic Discounts

Let me know if you have any questions. Even if you don't use my app, I can probably still help you in this thread.

Founder, Regios Discounts app (4.9 stars, 59 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer

Mike5241
Explorer
53 0 12

Hi Irfan3,

 

The following tip worked like a charm for me in the Dawn theme:

https://www.linkedin.com/pulse/how-offer-automatic-discounts-specific-customers-shopify-dematis-tdr1...

 

I hope it helps,

Mike

Jibberjabber
Visitor
1 0 0

Hi Mike,

That's exactly what I was looking for. You've made my day.

Thanks for sharing!

WVunderink
Shopify Partner
2 0 0

Thank you, this is the perfect workaround! I'm actually shocked that Shopify has not implemented a built-in feature like this, which would work wonders for Wholesale-oriented Shopify stores and obviate the need for a lot of rickety, glitchy third-party apps.

 

tobebuilds
Shopify Partner
457 32 120

This will only work if the customer is logged in by the time they visit the page.

 

If not, then when they visit the checkout page and enter their email, they will still have to enter the discount code manually, because you can't extend the checkout with custom code on a non-Plus plan.

 

In addition, that code snippet has no error handling, so if applying the discount via the AJAX API doesn't work for some reason, you won't know, and the customer will still have to manually enter the code at checkout.

Founder, Regios Discounts app (4.9 stars, 59 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
WVunderink
Shopify Partner
2 0 0

Ok, I should have said "this is the perfect workaround for my very specific needs!" 

 

For context, I'm running a wholesale storefront with customers in various discount groups. Customers are required to login before browsing the site or checking out, so that's not a problem. 

 

As for error handling, we invoice customers after processing orders rather than collecting payment at checkout. So if the customer's discount is not applied at checkout, it doesn't actually affect the amount collected—our customer service team will invoice the customer at the proper price level.

 

Would you like to suggest a solution for error handling in case others need to use this workaround?

tobebuilds
Shopify Partner
457 32 120

If that solution works for your needs, then genuinely, I'm glad. Software subscriptions can add up, so if you can get away with not using an app, that's great.

 

As far as error handling goes, you have a couple of options if the discount application doesn't work:

  • Retrying the `fetch` call periodically (ideally using an "exponential backoff" strategy)
  • Displaying an alert to customers to let them know that the discount wasn't applied, and that they will still have to manually apply it at checkout

The challenge here is that the `/discount/CODE` URL is not part of Shopify's AJAX Cart API (If I understand correctly, it just returns the page HTML), so it's possible it might give a successful HTTP status code in the response, even if the discount isn't applied.

 

So, you can check afterwards to see whether the cart has any discount applied, using the Cart API:

 

https://shopify.dev/docs/api/ajax/reference/cart#get-locale-cart-js

 

You'd need to check for the `total_discount` field, if present. If it's not present, you can assume the discount wasn't applied.

 

If you can code, this should be relatively straightforward. You can move the 2 `fetch` calls into a separate function, that will schedule itself again using `setTimeout` in case of a failure.

 

Shameless plug: For an option to create automatic discounts for customers with a specific tag, without any coding, try our app, Regios Automatic Discounts (4.9 stars, Built for Shopify).

Founder, Regios Discounts app (4.9 stars, 59 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer