Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

427
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda