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
User | RANK |
---|---|
2 | |
2 | |
2 | |
2 | |
1 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023