Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

426
Views
Ruby script to calculate discount using Shopify Scripts

I am using a script to calculate an addtional 5% off when the cart total is greater than $1000, but the variant price is already discounted by 25% and has a was/now pricing setup that is $29.95 was $39.95.

The problem is - i need for the script to discount the orginal item value of $39.95, not the discounted rate which is the new retail price.

Here is the script - i have tried to add 25% back to the line item price without success and there is no line item method that Shopify provides to use the orginal cart line item price in the dev docs - https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#line-item-methods

# Tiered Discounts by Spend Threshold 5% off when you spend $1000 or more
min_discount_order_amount_extra = Money.new(cents:100) * 1000 #number of dollars needed in cart to get the discount

DISCOUNT_PERCENT = 25

# calculate the discount to be applied
percent = Decimal.new(DISCOUNT_PERCENT/100) + 1

total = Input.cart.subtotal_price_was * percent

discount = if total > min_discount_order_amount_extra
              0.05 #discount percentage in decimal form
            else
              0
            end
message = "Another 5% saved"

# 30% off products excluding commercial items
Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  next if product.gift_card?
  next if line_item.variant.product.tags.any?{|x| ['commercial'].include?(x)};
  line_item.change_line_price(line_item.line_price * (1-discount), message: message) unless discount == 0
end

Output.cart = Input.cart

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!