Use Line Items Script for Different Discount Percents

Solved

Use Line Items Script for Different Discount Percents

NickBartelme
Tourist
10 1 1

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.

Screen Shot 2021-04-15 at 2.10.06 PM.png

Accepted Solution (1)

playwright-mike
Shopify Partner
72 18 33

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

Playwright | Create Shopify Scripts without writing code | https://playwrightapp.com
- Was my reply helpful? Please Like and Accept Solution.

View solution in original post

Reply 1 (1)

playwright-mike
Shopify Partner
72 18 33

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

Playwright | Create Shopify Scripts without writing code | https://playwrightapp.com
- Was my reply helpful? Please Like and Accept Solution.