Personalized checkout and custom promotions with Shopify Scripts
Hello,
I am attempting to create a line item discount script that discerns different percentage discounts for different customers. Some customers would get 50%, some would get 30%, etc.
Currently, I have a line item script working for a blanket 50% discount, whichI learned from the Product discount by customer tag tutorial.
This is a snippet of the edited part of the Ruby code from the tutorial.
DISCOUNTS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include,
customer_tags: ["BEK50Percent","3W50Percent"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["DEBC50Percent","3W50Percent"],
discount_type: :percent,
discount_amount: 50,
discount_message: "50% co-op applied",
},
]
I'd like to flesh this out to provide a certain subset of customers with 30% discount, not 50%. How could I accomplish this logic? Is simply copy+paste that whole set of code sufficient?
DISCOUNTS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include,
customer_tags: ["BEK50Percent","3W50Percent"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["DEBC50Percent","3W50Percent"],
discount_type: :percent,
discount_amount: 50,
discount_message: "50% co-op applied",
customer_tag_match_type: :include,
customer_tags: ["TEST30PERCENT"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["TEST30PERCENT"],
discount_type: :percent,
discount_amount: 30,
discount_message: "30% co-op applied",
},
]
This seems to work in the Script Editor, but I am a novice at Ruby and would like to get some feedback.
Solved! Go to the solution
This is an accepted solution.
Hi @NickBartelme,
I think you are close! Try this (adds a set of brackets in between the sets of parameters you have)
DISCOUNTS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include,
customer_tags: ["BEK50Percent","3W50Percent"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["DEBC50Percent","3W50Percent"],
discount_type: :percent,
discount_amount: 50,
discount_message: "50% co-op applied",
},
{
customer_tag_match_type: :include,
customer_tags: ["TEST30PERCENT"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["TEST30PERCENT"],
discount_type: :percent,
discount_amount: 30,
discount_message: "30% co-op applied",
}
]
Note: when you test, be sure that both the 50% discount and the 30% discount are working correctly.
Hope that is helpful!
Matthew
This is an accepted solution.
Hi @NickBartelme,
I think you are close! Try this (adds a set of brackets in between the sets of parameters you have)
DISCOUNTS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include,
customer_tags: ["BEK50Percent","3W50Percent"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["DEBC50Percent","3W50Percent"],
discount_type: :percent,
discount_amount: 50,
discount_message: "50% co-op applied",
},
{
customer_tag_match_type: :include,
customer_tags: ["TEST30PERCENT"],
product_selector_match_type: :include,
product_selector_type: :tag,
product_selectors: ["TEST30PERCENT"],
discount_type: :percent,
discount_amount: 30,
discount_message: "30% co-op applied",
}
]
Note: when you test, be sure that both the 50% discount and the 30% discount are working correctly.
Hope that is helpful!
Matthew
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025