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.
OmbyggtIt 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.
Klistra in det i Scripts-räddning och se vad som byggs
- Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
- Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
- 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
OmbyggtCUSTOMER_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.cartIdentifierat 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.
| Inställning | Värde | Konfigurationsnyckel |
|---|---|---|
| Offer type | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 25% off | tiers[0] |
| Target scope | all | target.scope |
| Customer scope | tags | customerTarget.scope |
| Customer tags | vip, wholesale | customerTarget.ids |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- 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.
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.
| Artikel | Antal | Styckpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Delsumma | $14.00 | |
| Rabatt | -$3.50 | |
| Summa | $10.50 | |
Inloggad som kund med taggen vip, wholesale.
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.
- take the same cart, but sign in as the customer with no tags
| Artikel | Antal | Styckpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Delsumma | $14.00 | |
| Summa | $14.00 | |
Utloggad, eller inloggad som kund utan taggar.
Customer tag gate, broken include
Kontrollera textenTAGS_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.cartWe 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
A discount for shoppers with no order history, or with enough of it.
A new-customer gate wrapped around a cheapest-item reward.
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.