Hoppa till innehåll
Script-exempel

Migrating a customer tag discount script

Nine independent sources write this the same way, and one very common variant is simply broken: it asks whether an array of tags is an ELEMENT of another array, which is never true, so the discount never fired for anyone.

Ombyggt
Vad detta Script gjorde

It applied the discount only when the signed-in customer carried one of the listed tags.

Handlare har skrivit det här på 2 olika sätt, och de betyder inte alla samma sak. Varje variant finns nedan med en egen varukorg och egna siffror.

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.

Customer tag gate, set intersection

Ombyggt
Den ursprungliga Ruby-koden

CUSTOMER_TAGS = ["vip", "wholesale"]
DISCOUNT_PERCENTAGE = 25

customer = Input.cart.customer

unless customer.nil?
  if !(CUSTOMER_TAGS & customer.tags.map(&:downcase)).empty?
    Input.cart.line_items.each do |line_item|
      next if line_item.variant.product.gift_card?
      line_item.change_line_price(
        line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
        message: "Member pricing"
      )
    end
  end
end

Output.cart = Input.cart
Vad det blir

Identifierat som Percentage off och ombyggt till ett erbjudande av typen volume. 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 typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 25% offtiers[0]
Target scopealltarget.scope
Customer scopetagscustomerTarget.scope
Customer tagsvip, wholesalecustomerTarget.ids
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Du kommer att få bekräfta
  • This script only applied to tagged customers. Set customer eligibility in the builder before publishing.
  • Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing.
  • Confirm which products this applies to. We could not read product targeting from the script.
Du kommer att få veta
  • Shopify matches customer tags exactly, including capital letters, while your Script lowercased them. Check the spelling of the tag before you publish.
  • Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
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
Rabatt-$3.50
Summa$10.50

Inloggad som kund med taggen vip, wholesale.

Beloppet som verktyget stämmer av dig mot

Före publicering frågar verktyget vad ditt gamla Script gjorde med en varukorg du redan har. Sätt den till 1 av Braided USB-C Cable à $14.00, så är svaret givet.

Rabatten är $3.50. Summan som kunden betalade är $10.50.

Jämförelsen är exakt, ned till minsta enhet i din valuta. Ett öre fel och publiceringen förblir stängd, vilket är hela poängen med steget.

Varukorgen som inte får ge något alls
  • take the same cart, but sign in as the customer with no tags
Varukorgen som inte får utlösa erbjudandet
ArtikelAntalStyckpris
Braided USB-C Cable1$14.00
Delsumma$14.00
Summa$14.00

Utloggad, eller inloggad som kund utan taggar.

Customer tag gate, broken include

Kontrollera texten
Den ursprungliga Ruby-koden

TAGS_NEEDED = ["vip", "wholesale"]

Input.cart.line_items.each do |line_item|
  next unless TAGS_NEEDED.include?(line_item.variant.product.tags)
  line_item.change_line_price(line_item.line_price * 0.8, message: "20% off")
end

Output.cart = Input.cart
Vad som händer med den här

We could not read this copy of your Script

This does not look like a Shopify Script. Paste the Ruby from the Script Editor, starting with the settings at the top of the file.

Ditt Script är förmodligen helt i sin ordning. Kopian som når verktyget är det inte, och verktyget gissar inte priser utifrån en skadad fil.

Orsaksnyckel: input.notAScript

Det finns ingen varukorg att testa här, eftersom ingenting byggs. Att klistra in det här ger meddelandet ovan och ingen kampanj alls.

Vanliga frågor

Will Stackable rebuild this script?
It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $3.50 off, and checkout charges $10.50.
What will I have to check before publishing?
This script only applied to tagged customers. Set customer eligibility in the builder before publishing. Your Script skipped gift cards. We cannot detect gift cards yet, so exclude them by hand in targeting before publishing. Confirm which products this applies to. We could not read product targeting from the script. Shopify matches customer tags exactly, including capital letters, while your Script lowercased them. Check the spelling of the tag before you publish. Your Script skipped gift cards and we cannot detect them, so gift cards are discounted unless you exclude them in targeting.
What happens to the part you cannot rebuild?
We could not read this copy of your Script. This does not look like a Shopify Script. Paste the Ruby from the Script Editor, starting with the settings at the top of the file.

Besläktade Script-former

First order discount

A discount for shoppers with no order history, or with enough of it.

First time customer, cheapest item

A new-customer gate wrapped around a cheapest-item reward.

Lifetime spend discount

A reward for customers who had spent enough over their lifetime.

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.