注文の確認メールの振り分けを商品と決済方法に合わせて行いたい

Topic summary

Shopifyの注文確認メールで、商品と決済方法の組み合わせに応じて文面を振り分ける方法についての質問と解決。

要件:

  • Dawnテーマを使用
  • 商品A/B/Cと決済方法(クレジットカード/銀行振込)の組み合わせで計6パターンのメール文面を振り分けたい

問題点:

  • 初期コードでは振り分けが正しく動作していなかった
  • Liquidテンプレートのロジックに不具合があった

解決策:
Qcoltd氏が修正コードを提供:

  • 各商品フラグ(has_item_a等)をfalseで初期化
  • line_itemsをループして商品を判定
  • 各商品ごとにorder.transactions[0].gatewayで決済方法を取得
  • 条件分岐で適切なメール文面を表示

結果:

  • 質問者は解決を確認し、感謝の意を表明
  • 実装前の検証テストが推奨された
Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

お世話になります。

コーディングについて初心者となります。初歩的な質問かもしれません。

テーマはDawnを使用しております。

商品と決済方法に合わせて何パターンかのメールの文面を振り分けたいと考えております。

たとえば、商品A・B・Cと3種類ありましたら計6種類のメールの文面を振り分けたいと考えております。

1.商品Aのクレジットカード決済

2.商品Aの銀行決済

3.商品Bのクレジットカード決済

4.商品Bの銀行決済

5.商品Cのクレジットカード決済

6.商品Cの銀行決済

現状、以下のようなコードを書いたのですが、うまく振り分けができておりません。

{% for line in subtotal_line_items %}
{% if line.title contains '商品A' %}
{% assign has_item_a = true %}
{% endif %}
{% if line.title contains '商品B' %}
{% assign has_item_b = true %}
{% endif %}
{% if line.title contains '商品C' %}
{% assign has_item_c = true %}
{% endif %}
{% endfor %}

{% if has_item_a %}
    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_a = false %}

        商品A銀行振込の文章

    {% else %}

     商品Aクレジットカードの文章

    {% endif %}

{% elsif has_item_b %}

    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_b = false %}

        商品B銀行振込の文章

    {% else %}

     商品Bクレジットカードの文章

    {% endif %}

{% elsif has_item_c %}

    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_c = false %}

        商品C銀行振込の文章

    {% else %}

     商品Cクレジットカードの文章

    {% endif %}
 {% endif %}

何時間も苦戦しているのですが、一向に解決できずにおります。

ご教授いただけますと幸いです。

@KDesign

注文の確認メールで文面を変更したい件ですが、記載いただいたコードを元に下記のように調整させていただきました。

{% assign has_item_a = false %}
{% assign has_item_b = false %}
{% assign has_item_c = false %}

{% for line in line_items %}
  {% if line.title contains '商品A' %}
    {% assign has_item_a = true %}
  {% endif %}
  {% if line.title contains '商品B' %}
    {% assign has_item_b = true %}
  {% endif %}
  {% if line.title contains '商品C' %}
    {% assign has_item_c = true %}
  {% endif %}
{% endfor %}

{% if has_item_a %}
  {% assign gateway_a = order.transactions[0].gateway %}
  {% if gateway_a == "Bank Deposit" %}
    商品Aの銀行振込の文章
  {% else %}
    商品Aのクレジットカードの文章
  {% endif %}
{% endif %}

{% if has_item_b %}
  {% assign gateway_b = order.transactions[0].gateway %}
  {% if gateway_b == "Bank Deposit" %}
    商品Bの銀行振込の文章
  {% else %}
    商品Bのクレジットカードの文章
  {% endif %}
{% endif %}

{% if has_item_c %}
  {% assign gateway_c = order.transactions[0].gateway %}
  {% if gateway_c == "Bank Deposit" %}
    商品Cの銀行振込の文章
  {% else %}
    商品Cのクレジットカードの文章
  {% endif %}
{% endif %}

大きな変更点としては、商品毎にif文を書かせていただきました。

コードの検証テストはできておりませんので、ご利用時は実際にチェックください。

ご参考まで。

(キュー小坂)

1 Like

うまくいきました!

本当に本当に感謝いたします。

ありがとうございます。