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.
ReconstruitIt applied the discount only when the signed-in customer carried one of the listed tags.
Les marchands ont écrit ceci de 2 façons différentes, et elles ne veulent pas toutes dire la même chose. Chaque variante figure ci-dessous avec son propre panier et ses propres chiffres.
Collez-le dans Sauvetage des Scripts et regardez ce qu'il reconstruit
- Copiez le Ruby avec le bouton placé à côté de chaque Script de cette page.
- Dans votre interface Shopify, ouvrez Stackable, puis Outils, puis Sauvetage des Scripts.
- Collez-le, lisez ce que l'outil annonce qu'il va construire et comparez-le aux réglages de cette page.
Sauvetage des Scripts fait partie du forfait Pro. Rien n'est publié tant que vous n'avez pas indiqué la remise de votre ancien Script et que les deux chiffres ne correspondent pas au centime près.
Customer tag gate, set intersection
ReconstruitCUSTOMER_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.cartReconnu comme Percentage off et reconstruit en offre de type volume. Voici les vraies clés de configuration avec lesquelles l'offre est enregistrée, pour que vous puissiez comparer votre propre reconstruction champ par champ.
| Réglage | Valeur | Clé de configuration |
|---|---|---|
| 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.
Construit sur notre boutique de démonstration publique, Meridian Goods, pour que chaque prix ici puisse être reproduit plutôt que cru sur parole. La remise ci-dessous est ce que le moteur qui tourne au paiement calcule pour ce panier précis.
| Article | Qté | Prix unitaire |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Sous-total | $14.00 | |
| Remise | -$3.50 | |
| Total | $10.50 | |
Connecté en tant que client portant le tag vip, wholesale.
Avant la publication, l'outil demande ce que votre ancien Script faisait à un panier que vous avez déjà. Réglez-le sur 1 de Braided USB-C Cable à $14.00 et la réponse est fixée.
La remise est de $3.50. Le total payé par l'acheteur est de $10.50.
La comparaison est exacte, jusqu'à la plus petite unité de votre devise. Un centime d'écart et la publication reste bloquée, ce qui est tout l'intérêt de l'étape.
- take the same cart, but sign in as the customer with no tags
| Article | Qté | Prix unitaire |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Sous-total | $14.00 | |
| Total | $14.00 | |
Déconnecté, ou connecté en tant que client sans tag.
Customer tag gate, broken include
Vérifiez le collageTAGS_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.
Votre Script est probablement très bien. La copie qui parvient à l'outil ne l'est pas, et il ne devinera pas les prix à partir d'un fichier abîmé.
Clé du motif : input.notAScript
Il n'y a pas de panier à tester ici, puisque rien n'est construit. Coller ceci produit le message ci-dessus et aucune campagne.
Questions fréquentes
- 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.
Formes de Script apparentées
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.
Collez votre Script et voyez sa reconstruction
La reconstruction est comparée au montant que facturait votre ancien Script avant que vous puissiez la publier.