Spring til indhold
Script-eksempler

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.

Genopbygget
Hvad dette Script gjorde

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

Handlende har skrevet det her på 2 forskellige måder, og de betyder ikke alle det samme. Hver variant står nedenfor med sin egen kurv og sine egne tal.

Prøv det i din egen butik

Indsæt det i Scripts-redning, og se hvad der bliver bygget

  1. Kopiér Ruby-koden med knappen ved siden af ethvert Script på siden.
  2. Åbn Stackable i Shopify-administrationen, derefter Værktøjer og så Scripts-redning.
  3. Indsæt det der, læs hvad værktøjet siger, det vil bygge, og hold det op mod indstillingerne på denne side.

Scripts-redning hører til Pro-abonnementet. Intet bliver udgivet, før du oplyser, hvad dit gamle Script gav i rabat, og de to beløb stemmer helt ned på øret.

Customer tag gate, set intersection

Genopbygget
Den oprindelige Ruby-kode

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
Hvad det bliver til

Genkendt som Percentage off og genopbygget som et tilbud af typen volume. Det her er de rigtige konfigurationsnøgler, som tilbuddet gemmes med, så du kan tjekke din egen genopbygning felt for felt.

Hver indstilling, skrevet ud
IndstillingVærdiKonfigurationsnøgle
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 bliver bedt om at bekræfte
  • 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 får det at vide
  • 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.
Kurven, der beviser det

Bygget i vores offentlige demobutik, Meridian Goods, så hver pris her kan efterregnes i stedet for at blive taget på tro. Rabatten nedenfor er det, som den samme motor, der kører i kassen, beregner for præcis denne kurv.

Kurven, der udløser dette tilbud, og hvad det koster
VareAntalStykpris
Braided USB-C Cable1$14.00
Subtotal$14.00
Rabat-$3.50
Total$10.50

Logget ind som kunde med tagget vip, wholesale.

Beløbet, som værktøjet holder dig op mod

Inden du udgiver, spørger værktøjet, hvad dit gamle Script gjorde ved en kurv, du allerede har. Sæt den til 1 af Braided USB-C Cable à $14.00, så ligger svaret fast.

Rabatten er $3.50. Det beløb, kunden betalte, er $10.50.

Sammenligningen er præcis, helt ned til den mindste enhed i din valuta. En øre ved siden af, og udgivelsen forbliver spærret, hvilket er hele pointen med trinnet.

Kurven, der ikke må give noget
  • take the same cart, but sign in as the customer with no tags
Kurven, der ikke må udløse dette tilbud
VareAntalStykpris
Braided USB-C Cable1$14.00
Subtotal$14.00
Total$14.00

Logget ud, eller logget ind som kunde uden tags.

Customer tag gate, broken include

Tjek det indsatte
Den oprindelige Ruby-kode

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
Hvad der sker med denne

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.

Dit Script fejler sandsynligvis ikke noget. Det gør den kopi, der når frem til værktøjet, og det gætter ikke priser ud fra en beskadiget fil.

Årsagsnøgle: input.notAScript

Der er ingen kurv at teste her, fordi der ikke bliver bygget noget. At indsætte det her giver beskeden ovenfor og slet ingen kampagne.

Ofte stillede spørgsmål

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ægtede Script-typer

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.

Indsæt dit Script og se det blive genopbygget

Genopbygningen holdes op mod det beløb, dit gamle Script opkrævede, før du kan udgive den.

Vi bruger essentielle cookies til at drive dette site, og kun med din tilladelse, analysecookies til at forstå trafik. Læs vores Cookiepolitik.