# 商品ごとにフォーム入力を追加したい

**URL:** <https://community.shopify.com/t/topic/177214>\
**Category:** 技術的なQ＆A\
**Created:** [December 18, 2022, 4:20pm UTC](https://community.shopify.com/t/topic/177214 "2022-12-18T16:20:01Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

**課題:**
Shopifyの商品ページにカスタムフォーム入力（line item property）を追加したが、一部の商品では不要なため非表示にしたい。

**試したこと:**
- UI Elements Generatorを使用してフォーム追加に成功
- `myproducts.liquid`をブロックとして購入ボタン上に読み込む形で実装
- しかし、表示される商品でもカートにデータが渡らない問題が発生

**解決策:**
_osamu_iwasakiが提案した方法：
- 商品ごとにメタフィールドを作成して出し分けを行う
- `{% if product.metafields.custom.receipt == true %}`のような条件分岐でline item propertyのHTMLを制御
- コードは`<form>`タグ（Liquidでは`{% form %}`）内に記述する必要がある

**結果:**
質問者は解決し、感謝のコメントで終了。

<div class="post-metadata">

**Author:** ![reiko888](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@reiko888](https://community.shopify.com/u/reiko888)\
**Post date:** [December 18, 2022, 4:20pm UTC](https://community.shopify.com/t/topic/177214/1 "2022-12-18T16:20:01Z")

</div>

お世話になっております。  
以下のページから、商品ページの入力からカートへ渡すフォームを追加することができました。  
[https://ui-elements-generator.myshopify.com/pages/line-item-property](https://ui-elements-generator.myshopify.com/pages/line-item-property)

ところが、商品によってはその入力が必要では無いものがあり、

非表示にしたいので「myproducts.liquid」を追加し、購入ボタンの上に読み込めるブロックにしたいと思ったのですが、表示はされるものの、カートにはデータを渡せませんでした。

どこに、問題があるのか、ご教示いただけたら助かります。  
よろしくお願いいたします。

```markup

  

  

{% schema %}
  {
    "name": "myproducts",

  "presets": [
   {
     "name": "希望確認"
   }
 ]
}
{% endschema %}

```

---

<div class="post-metadata">

**Author:** ![\_osamu\_iwasaki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/_osamu_iwasaki/32/272617_2.png) [@\_osamu\_iwasaki](https://community.shopify.com/u/_osamu_iwasaki)\
**Post date:** [December 20, 2022, 7:04am UTC](https://community.shopify.com/t/topic/177214/2 "2022-12-20T07:04:52Z")

</div>

コード全体みてないので推測ですが、  
HTML上の（Liquidでは{% form %}{% endform %}）タグの間に、

上記のline item propertyが入っていないのではないでしょうか？

あと関係なさそうですが、下部のschemaは機能してなさそうです。

---

<div class="post-metadata">

**Author:** ![reiko888](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@reiko888](https://community.shopify.com/u/reiko888)\
**Post date:** [December 20, 2022, 1:27pm UTC](https://community.shopify.com/t/topic/177214/3 "2022-12-20T13:27:33Z")

</div>

@_osamu_iwasaki  
返信をいただき、ありがとうございます。すみません、質問ですが  
追加のコードを直接カートのmain-product.liquidに書くとカートまで呼び込めたのですが、  
ブロックにして、商品ごとに呼びたいのですが、その場合も、追加した  
myproducts.liquidをmain-product.liquidの中に記述する必要があるのでしょうか？

---

<div class="post-metadata">

**Author:** ![\_osamu\_iwasaki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/_osamu_iwasaki/32/272617_2.png) [@\_osamu\_iwasaki](https://community.shopify.com/u/_osamu_iwasaki)\
**Post date:** [December 21, 2022, 1:46am UTC](https://community.shopify.com/t/topic/177214/4 "2022-12-21T01:46:34Z")

</div>

その場合は、商品ごとにメタフィールド作って出し分けをするといいと思います。

 ![meta.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/5/4/54dab129be77c7daf327d29092fca812c66d244a.png)

```markup
{% if product.metafields.custom.receipt == true %}
line item propertyのHTML
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![reiko888](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@reiko888](https://community.shopify.com/u/reiko888)\
**Post date:** [December 21, 2022, 7:25am UTC](https://community.shopify.com/t/topic/177214/5 "2022-12-21T07:25:22Z")

</div>

ありがとうございます！できました。  
大変助かりました。
