# アカウント画面(注文履歴一覧が表示される画面)で、特定のタグがついた商品の購入履歴があるユーザに対して、特別なボタンを表示したい

**URL:** <https://community.shopify.com/t/topic/283752>\
**Category:** 技術的なQ＆A\
**Tags:** javascript, css, html\
**Created:** [January 10, 2024, 6:52am UTC](https://community.shopify.com/t/topic/283752 "2024-01-10T06:52:07Z")\
**Posts on this page:** 2\
**Page:** 1

## AI-generated summary

- 目的: Dawnテーマのアカウント（注文履歴一覧）画面で、特定タグ付き商品を購入済みユーザにのみ特別ボタンを表示したい。
- 質問点: 1) 判定に使う変数は何か。2) 条件分岐の具体的な書き方。
- 提案された実装: Dawn 12.0.0のSections > main-account.liquid内でcustomer.ordersを走査し、該当のHTML位置に条件を追加。
- ロジック: 各order内でisTagIncluded=falseを初期化し、order.line_itemsをループ。line_item.product.tagsに対象タグが含まれるかを検査し、含まれる場合はtrueに設定。
- 表示制御: isTagIncludedがtrueのときのみ、ボタンなどの特別な要素を描画する。
- 技術補足: Liquid（Shopifyのテンプレート）での記述。product.tagsは商品に付与されたタグの配列で、containsで部分一致判定。
- 注意事項: 回答コードは未検証であり、ミスタイプ等で動作しない可能性があるため要テスト。
- 状態: 提案は提示済みだが、採用・解決報告はなく、スレッドは未確定。添付画像は表示位置の参考。

<div class="post-metadata">

**Author:** ![torano](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@torano](https://community.shopify.com/u/torano)\
**Post date:** [January 10, 2024, 6:52am UTC](https://community.shopify.com/t/topic/283752/1 "2024-01-10T06:52:07Z")

</div>

使用しているテーマはDawnです

添付画像のアカウント(太字)の右のエリアに、条件分岐によってボタンを表示させたいです

1. どのような変数を使えば、ユーザが特定のタグのついた商品を購入したか判別できるでしょうか？

2. 条件分岐はどのように設定すれば良いでしょうか？

以上2点、知見ある方ぜひ回答をお願いします

 ![スクリーンショット 2024-01-10 15.51.26.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/2/8/281d947fff034b4eb6bde8f97a42d4f189e3b30e.png)

---

<div class="post-metadata">

**Author:** ![Qcoltd](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/qcoltd/32/900_2.png) [@Qcoltd](https://community.shopify.com/u/Qcoltd)\
**Post date:** [January 11, 2024, 12:34pm UTC](https://community.shopify.com/t/topic/283752/2 "2024-01-11T12:34:50Z")

</div>

@torano 様

Dawn 12.0.0を例に挙げます。

セクションズ \> main-account.liquid

の中に、

```markup
{%- for order in customer.orders -%}
- 中略 - 
{%- endfor -%}

```

という記載があるはずです。

このfor文内のお目当てのHTMLの箇所で、下記のようにすると条件分岐できるかと思います。

```markup
{%- for order in customer.orders -%}
- 中略 - 
  {% assign isTagIncluded = false %}
  {% for line_item in order.line_items %}
    {% if line_item.product.tags contains "対象のタグ" %}
      {% assign isTagIncluded = true %}
    {% endif %}
  {% endfor %}
  {% if isTagIncluded %}
      // 商品が対象のタグを持つ場合の処理
  {% endif %}
- 中略 - 
{%- endfor -%}

```

動作検証はしておりませんので、

ミスタイプなどで動かない可能性もありますが、

ご参考まで。

(キュー田辺)
