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.
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:
In your Shopify admin, go to Discounts and click on the “Create automatic discount” button.
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.
Set the discount amount and choose whether it will be a percentage or a fixed amount.
Set the start and end dates for the discount, or choose to make it ongoing.
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.
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:
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:
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).