Home / Function Lab / How to add an Automatic Product Discount for tagged customers.

How to add an Automatic Product Discount for tagged customers.

1. Click on "Automatic discounts" and click the "Add" button. Enter a name for your Discount. E.g. "VIP Discount".

2. Select the "Tagged Customer Product Discount" example from the drop down selector in the "Rules" section:

3. Edit your JSON rule:

Event

Type: This the type of discount.  Here we're using a product_discount. Leave this as-is. Possible options are displayed in the editor:

Params:

value: (integer) The amount off.

discount_type: (enum) options are fixed / percentage.

message: (string) what's displayed to the customer

handles: (array) Array of product handles that this discount applies to. You can retrieve these from the Shopify admin. 

Conditions:

In order to only apply this to customers with a specific tag*, we include this condition:

*we will specify this tag in the "Variables" section next.

Variables

Expand the variables section and enter the customer tag that this discount will apply to. If you leave this blank, then no customer or product tag is required for the discount to apply.

4.  Save your rule.

 

5. Test your rule

We've provided a sample input. Click "Run". If the product handle in the Input matches the one in the rule, you should see a discount returned.  

Changing the hasAnyTag reference in the input to false, should return no discount in the Output. (this simulates a customer who doesn't have the matching tags).

"buyerIdentity": {
"customer": {
"hasAnyTag"false
}
},
6.  Check your rule size.
The size of the cart and the complexity of the rule can affect the time it takes to execute a function. This is called Instruction Cost, and is limited to 11 million instructions before it fails to run.  Click the calculator to check that your function is under the instruction limit.
7.  Push your discount to Shopify
Return to the list of Automatic Discounts by clicking on the "Automatic Discounts" and toggle the discount to on:
Back to blog