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
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024