How enable Shopify 讓客戶結帳時同時使用兩個以上 Copuon 條件

這是個常見的需求,但 Shopify 原生有嚴格限制。讓我說明各種解決方案。

Shopify 原生限制

Shopify 預設只允許結帳時使用一個折扣碼。這是平台層級的限制,無法透過設定直接繞過。


解決方案

方案一:使用 Shopify Functions(推薦,Shopify Plus 或標準方案皆可)

Shopify Functions 允許你建立自訂折扣邏輯,可以在單一折扣碼內組合多種條件

# shopify.extension.toml
api_version = "2024-01"

[extensions.capabilities]
network_access = false

[[extensions]]
name = "Combined Discount"
type = "function"
build_path = "dist/index.js"

[extensions.targeting]
target = "purchase.discount.order"
// src/index.js
export function run(input) {
  const cart = input.cart;
  const discounts = [];
  
  // 條件 1:滿額折扣
  const subtotal = parseFloat(cart.cost.subtotalAmount.amount);
  if (subtotal >= 3000) {
    discounts.push({
      type: 'percentage',
      value: 10,
      message: '滿 $3000 享 9 折'
    });
  }
  
  // 條件 2:特定商品折扣
  const hasTargetProduct = cart.lines.some(line => 
    line.merchandise.product.hasTag('summer-sale')
  );
  if (hasTargetProduct) {
    discounts.push({
      type: 'percentage', 
      value: 5,
      message: '夏季商品額外 95 折'
    });
  }
  
  // 條件 3:會員折扣
  if (input.customer?.hasTag('vip')) {
    discounts.push({
      type: 'percentage',
      value: 5,
      message: 'VIP 會員專屬優惠'
    });
  }
  
  // 合併計算折扣
  return {
    discounts: discounts.map(d => ({
      value: { percentage: { value: d.value.toString() } },
      message: d.message,
      targets: [{ orderSubtotal: { excludedVariantIds: [] } }]
    }))
  };
}

方案二:使用 Automatic Discounts 疊加

Shopify 允許自動折扣折扣碼同時生效。設定方式:

步驟 1:建立自動折扣

  • 進入 Shopify Admin → Discounts → Create discount
  • 選擇 “Automatic discount”
  • 設定條件(例如:滿 $2000 自動折 $200)

步驟 2:建立折扣碼

  • 建立一般的折扣碼(例如:SUMMER20 享 8 折)

效果: 當顧客符合自動折扣條件,同時輸入折扣碼,兩者會疊加。

購物車小計:$3000
├── 自動折扣:滿額折 $200
├── 折扣碼 SUMMER20:8 折 (-$560)
└── 最終金額:$2240

限制: 最多只能疊加 1 個自動折扣 + 1 個折扣碼。


方案三:Shopify Scripts(僅限 Shopify Plus)

如果你是 Shopify Plus 商家,可以使用 Scripts Editor:

# 多重折扣 Script
DISCOUNTS = [
  { code: "SAVE10", type: :percent, value: 10 },
  { code: "EXTRA5", type: :percent, value: 5 },
  { code: "FLAT100", type: :fixed, value: 100 }
]

Input.cart.discount_code

# 取得所有適用的折扣(透過 line item properties 傳遞)
applied_codes = Input.cart.line_items.flat_map do |item|
  item.properties.select { |p| p.name.start_with?("_discount_") }.map(&:value)
end.uniq

total_discount = 0

applied_codes.each do |code|
  discount = DISCOUNTS.find { |d| d[:code] == code }
  next unless discount
  
  if discount[:type] == :percent
    total_discount += Input.cart.subtotal_price * (discount[:value] / 100.0)
  else
    total_discount += Money.new(cents: discount[:value] * 100)
  end
end

Input.cart.line_items.each do |item|
  item.change_line_price(item.line_price - (total_discount / Input.cart.line_items.size), message: "組合優惠")
end

Output.cart = Input.cart

方案四:使用第三方 App

幾個支援多折扣碼的熱門 App:

App 價格 特點
Unlimited Discount Codes $9.99/月 支援無限折扣碼疊加
Discount Ninja $49/月起 進階促銷引擎,支援複雜規則
Bold Discounts $19.99/月 自動折扣 + 疊加功能
Stackable Discounts $7.99/月 專門解決多折扣疊加問題

方案五:變通做法 - 組合折扣碼

如果不想用 App,可以預先建立組合折扣碼:

單一折扣:
- SUMMER20 (20% off)
- VIP10 (10% off)
- FREE_SHIP (免運)

組合折扣碼(預先計算好):
- SUMMER20_VIP → 28% off (20% + 10% 疊加計算)
- SUMMER20_SHIP → 20% off + 免運
- VIP10_SHIP → 10% off + 免運
- ALL_IN_ONE → 28% off + 免運

然後用 GTM 根據用戶條件自動帶入對應的組合碼:

<script>
(function() {
  var urlParams = new URLSearchParams(window.location.search);
  var codes = [];
  
  // 收集所有折扣碼參數
  if (urlParams.get('summer')) codes.push('summer');
  if (urlParams.get('vip')) codes.push('vip');
  if (urlParams.get('freeship')) codes.push('ship');
  
  // 對應到組合折扣碼
  var comboMap = {
    'summer': 'SUMMER20',
    'vip': 'VIP10',
    'ship': 'FREE_SHIP',
    'summer,vip': 'SUMMER20_VIP',
    'summer,ship': 'SUMMER20_SHIP',
    'vip,ship': 'VIP10_SHIP',
    'summer,vip,ship': 'ALL_IN_ONE'
  };
  
  var key = codes.sort().join(',');
  var finalCode = comboMap[key];
  
  if (finalCode) {
    window.location.href = '/discount/' + finalCode + '?redirect=' + encodeURIComponent(window.location.pathname);
  }
})();
</script>

建議方案選擇

情境 推薦方案
標準方案 + 簡單需求 方案二(自動折扣 + 折扣碼)
標準方案 + 複雜規則 方案四(第三方 App)
Shopify Plus 方案三(Scripts)或方案一(Functions)
不想付費 + 有開發能力 方案五(組合折扣碼)

你目前是哪種 Shopify 方案?需要支援的折扣組合邏輯大概是什麼樣的?我可以給更具體的實作建議。