Discussing APIs and development related to customers, discounts, and order management.
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
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.
@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.
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:
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
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!
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:
But TLDR, you have 2 options at this point:
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.
Hi Irfan3,
The following tip worked like a charm for me in the Dawn theme:
I hope it helps,
Mike
Hi Mike,
That's exactly what I was looking for. You've made my day.
Thanks for sharing!
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.
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.
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?
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:
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).