How do I limit a script to execute once per customer? Script Editor

Solved

How do I limit a script to execute once per customer? Script Editor

IliaZ
Shopify Partner
11 3 1

What I want:

  • I have created a script in the Script Editor that makes your first line item free. I want this script to execute once per customer.

My question:

  • What is the syntax to limit a script to execute once per customer for the Script Editor?

Business use case:

  • Without adding this functionality to my script, a customer could checkout with 1 item free... but then they could begin shopping again and checkout with a new cart with the first line item free... that means they could get 10 free items from 10 different checkouts.

Thanks for your time and thoughts!

P.S. Setting up a discount code won't work for my use case

Accepted Solution (1)

IliaZ
Shopify Partner
11 3 1

This is an accepted solution.

Got an answer from Stackoverflow  which worked for me:

 

 

// Any kind of solution could only work if Accounts are required otherwise you can't track the history of orders.

//There are two possible solutions

// You create a flow that assigns a tag to a customer when they receive a gift. You check // for the tag

Input.cart.customer.tags.include?('gift_received') and don't apply the discount.

// If your case is just 'Gift on the first order' you can just check 

Input.cart.customer.orders_count > 0 and that's it.

 

View solution in original post

Reply 1 (1)

IliaZ
Shopify Partner
11 3 1

This is an accepted solution.

Got an answer from Stackoverflow  which worked for me:

 

 

// Any kind of solution could only work if Accounts are required otherwise you can't track the history of orders.

//There are two possible solutions

// You create a flow that assigns a tag to a customer when they receive a gift. You check // for the tag

Input.cart.customer.tags.include?('gift_received') and don't apply the discount.

// If your case is just 'Gift on the first order' you can just check 

Input.cart.customer.orders_count > 0 and that's it.