Hoppa till innehåll
Script-exempel

Migrating an amount off shipping script

Two classes in the generator library are one word apart and inverted. On a $30 rate, one leaves the shopper paying $25 and the other leaves them paying $5, and the bodies are almost the same ternary.

Ombyggt
Vad detta Script gjorde

It subtracted a fixed sum from every delivery rate, never taking it below free.

Testa det i din egen butik

Klistra in det i Scripts-räddning och se vad som byggs

  1. Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
  2. Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
  3. Klistra in det där, läs vad verktyget säger att det ska bygga och jämför med inställningarna på den här sidan.

Scripts-räddning ingår i Pro-planen. Ingenting publiceras förrän du anger vad ditt gamla Script gav i rabatt och båda beloppen stämmer på öret.

Detta Script

Ombyggt

Riskabelt par D4. Den här filen och dess motpart ser nästan likadana ut och beter sig olika, så läs båda innan du avgör vilken du har.

Den ursprungliga Ruby-koden

# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP

class FixedDiscount
  def initialize(amount, message)
    @amount = Money.new(cents: 100) * amount
    @message = message
  end

  def apply(rate)
    rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
    rate.apply_discount(rate_discount, { message: @message })
  end
end

CAMPAIGNS = [
  ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
].freeze

CAMPAIGNS.each do |campaign|
  campaign.run(Input.shipping_rates, Input.cart)
end

Output.shipping_rates = Input.shipping_rates
Vad det blir

Identifierat som Shipping discount och ombyggt till ett erbjudande av typen free_shipping. Det här är de verkliga konfigurationsnycklarna som erbjudandet sparas med, så du kan stämma av din egen ombyggnad fält för fält.

Varje inställning, utskriven
InställningVärdeKonfigurationsnyckel
Offer typefree_shippingtype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> $5.00 off eachtiers[0]
Target scopealltarget.scope
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Du kommer att få bekräfta
  • Confirm which products this applies to. We could not read product targeting from the script.
Du kommer att få veta
  • This discounts every shipping rate at checkout, not one named rate.
Varukorgen som bevisar det

Byggd i vår publika demobutik, Meridian Goods, så att varje pris här går att räkna efter i stället för att tas på förtroende. Rabatten nedan är vad samma motor som kör i kassan räknar fram för exakt den här varukorgen.

Varukorgen som utlöser erbjudandet, och vad det kostar
ArtikelAntalStyckpris
Braided USB-C Cable1$14.00
Delsumma$14.00
Leverans, normalt $6.90$1.90
Summa$14.00

Utloggad, eller inloggad som kund utan taggar.

Beloppet som verktyget stämmer av dig mot

This rebuild only changes shipping. We price shipping against a sample rate rather than the rate your shopper saw, so there is no figure here we could honestly compare. Publishing records that the amount was not checked.

Varukorgen som inte får ge något alls

This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.

Två filer som ser likadana ut

Varje par nedan är samma Script-form skriven på två sätt. De skiljer sig åt på en eller två rader och gör olika saker, så läs båda innan du avgör vilken du har.

Farligt par D4

Shipping fixed amount off (D4)

Ombyggt

Byggs om till ett free_shipping-erbjudande.

Fraktbesparing i sin egen varukorg: $5.00

Rader som skiljer sig
class FixedDiscount
    rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
  ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
Läs Amount off shipping

Shipping fixed price (D4)

Stöds inte än

Byggs inte om. We have not built this yet

Rader som skiljer sig
class FixedPriceDiscount
    rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
  ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
Läs Flat rate shipping

Vanliga frågor

Will Stackable rebuild this script?
Yes. Every spelling on this page is rebuilt today as a free_shipping offer, and the cart above is the one that proves it.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $5.00 off, and checkout charges $14.00 plus $1.90 delivery.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script. This discounts every shipping rate at checkout, not one named rate.

Besläktade Script-former

Flat rate shipping

Every delivery rate rewritten to one price rather than reduced by an amount.

Percentage off shipping

A share taken off every delivery rate at checkout.

Free shipping over a threshold

Delivery drops to free once the cart is worth enough.

Klistra in ditt Script och se det byggas om

Ombyggnaden stäms av mot beloppet som ditt gamla Script tog ut innan du kan publicera den.

Vi använder nödvändiga cookies för att driva den här webbplatsen, och, bara med ditt tillstånd, analyscookies för att förstå trafiken. Läs vår Cookiepolicy.