# 商品ページのバリエーション在庫数表示を指定数以上の場合非表示にしたい

**URL:** <https://community.shopify.com/t/topic/149776>\
**Category:** 技術的なQ＆A\
**Created:** [September 8, 2022, 2:00am UTC](https://community.shopify.com/t/topic/149776 "2022-09-08T02:00:07Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

ShopifyのDebutテーマ商品ページで、バリエーション在庫が指定数（例：5個）以上の場合は非表示にしたいという要望。

Liquid（product-template.liquid）で条件分岐を追加すると初回表示は非表示になるが、バリエーション再選択時に5個以上でも在庫が表示される問題が発生。

技術的背景：ヘルプ記事の実装では、バリエーション選択後の在庫表示はtheme.jsのカスタマイズが制御。Liquidのみの変更では、JSによる再描画時の条件に反映されない。

対応策：theme.js内の条件「if (variantStock[variant.id] > 0」を、指定数以上は非表示になるよう閾値を組み込む（例：「> 0」を「< 5」に変更、または「>= 5」の場合は表示処理を行わない）。

最新の結果：JS側の条件を編集したところ解決。結論が出ており、未解決の点や追記事項はない。

<div class="post-metadata">

**Author:** ![Anonymous\_5668323578ab397108800f8626e31a2c](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Anonymous\_5668323578ab397108800f8626e31a2c](https://community.shopify.com/u/Anonymous_5668323578ab397108800f8626e31a2c)\
**Post date:** [September 8, 2022, 2:00am UTC](https://community.shopify.com/t/topic/149776/1 "2022-09-08T02:00:07Z")

</div>

お世話になります。

初投稿の為、内容に不備などがありましたら_ご容赦いただけますと幸いです。_

■使用しているテーマ

Debutのバージョン17.12.1

■現在の状態

ヘルプセンターで紹介されていた【[商品ページにバリエーションの残りの在庫を表示する](https://help.shopify.com/ja/manual/online-store/themes/themes-by-shopify/vintage-themes/customizing-vintage-themes/show-remaining-quantity)】を利用し、商品ページ内にてバリエーション選択時にそれぞれの在庫が表示されるようにしております。

■変更したいこと

上記の在庫表示設定を、在庫が指定数以上だった場合のみ非表示という条件を追加したいです。

■試した変更

5個以上の場合非表示にしたく下記コードを試しました。  
商品ページアクセス直後は非表示となるのですが、再度該当するバリエーションを選択すると、5個以上でも在庫数が表示されてしまいました。

変更後 ※product-template.liquid内です

```auto
<div class="inventoryWrapper">
 {% if current_variant.inventory_quantity > 5 and current_variant.inventory_management == 'shopify' %}
　{% elsif current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %}
　　<p>stock: {{ current_variant.inventory_quantity }}</p>
 {% endif %}
</div>

```

変更前 ※product-template.liquid内です

```auto
<div class="inventoryWrapper">
  {% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %}
    <p>Stock: {{ current_variant.inventory_quantity }}</p>
  {% endif %}
</div>

```

お手数をおかけしますが、変更が必要なコードの内容をご教示頂けますと幸いです。

次回確認が9/12以降になる場合がございます。宜しくお願い致します。

---

<div class="post-metadata">

**Author:** ![Anonymous\_3669bb4b7b6a3471042090ac49b19f2c](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/anonymous_3669bb4b7b6a3471042090ac49b19f2c/32/2990_2.png) [@Anonymous\_3669bb4b7b6a3471042090ac49b19f2c](https://community.shopify.com/u/Anonymous_3669bb4b7b6a3471042090ac49b19f2c)\
**Post date:** [September 8, 2022, 4:00am UTC](https://community.shopify.com/t/topic/149776/2 "2022-09-08T04:00:18Z")

</div>

@Anonymous_5668323578ab397108800f8626e31a2c

こんにちは！

[商品ページにバリエーションの残りの在庫を表示する](https://help.shopify.com/ja/manual/online-store/themes/themes-by-shopify/vintage-themes/customizing-vintage-themes/show-remaining-quantity)

の内容のtheme.jsのカスタマイズ部分にある

```auto
if (variantStock[variant.id] > 0 

```

の部分も併せて5個以上という条件にされておりますでしょうか？

もし編集されていないようでしたら、編集してください。

解決の手助けとなりましたら幸いです。

よろしくお願いします！

---

<div class="post-metadata">

**Author:** ![Anonymous\_5668323578ab397108800f8626e31a2c](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Anonymous\_5668323578ab397108800f8626e31a2c](https://community.shopify.com/u/Anonymous_5668323578ab397108800f8626e31a2c)\
**Post date:** [September 8, 2022, 6:51am UTC](https://community.shopify.com/t/topic/149776/3 "2022-09-08T06:51:44Z")

</div>

上記箇所を編集したところ、無事解決いたしました。  
この度はご回答ありがとうございました！
