PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How Do I Limit A Script To Execute Once Per Customer? Script Editor and Shopify

 June 30, 2022     ruby, shopify, shopifyscripts     No comments   

Issue

What I want:

  • I have created a script in the Script Editor that makes your first line item in a cart 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 through the use of the Script Editor app?

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 again... that means they could get 10 free items from 10 different checkouts.

Thanks for your time and thoughts!

P.S. Script is in Ruby. Also, Setting up a discount code won't work for my use case.

UPDATE

Thank you for your responses. I will be attempting these suggested updates this week and will post my results soon.

UPDATE 2

So the below suggestions and marked answer were all spot on except for one detail. The script editor keeps on running into some type of error even though the described syntax below is correct. Another stackoverflow answer suggested to use '&'.

So I ended up doing something like this:

customer = Input.cart.customer
if customer&.tags&.include?("gift_received")
...
end

This works for me. Thanks again for all your answers!


Solution

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

  1. 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.
  2. If your case is just 'Gift on the first order' you can just check Input.cart.customer.orders_count > 0 and that's it.


Answered By - Fabio Filippi
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,207,247

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing