# 在庫数に応じて表示テキストを変更したいです。

**URL:** <https://community.shopify.com/t/topic/168030>\
**Category:** 技術的なQ＆A\
**Created:** [November 15, 2022, 3:31pm UTC](https://community.shopify.com/t/topic/168030 "2022-11-15T15:31:07Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

商品詳細ページで在庫数に応じた表示テキストの変更方法についての質問です。

**目的:**
- 在庫1〜3個:「残り○個です。」と表示
- 在庫4〜5個:「残りわずか」と表示
- 在庫6個以上:在庫数を非表示

**使用環境:**
有料テーマ「Showcase」を使用中。現在は商品詳細ページに在庫数が表示される設定。

**試したコード:**
Liquidコードで条件分岐を試みたが、在庫5個以上でも「残りわずか」が表示されてしまう問題が発生。

**回答内容:**
フルバランスの園畑氏より、コードの条件式を修正する提案がありました。具体的には:
- `if current_variant.inventory_quantity > 3` の比較演算子を変更
- `elsif current_variant.inventory_quantity >= 5` を `elsif current_variant.inventory_quantity > 5` に修正

質問者は回答を受けて変更を試み、機能が正常に動作したことを報告し、解決済みとなりました。

<div class="post-metadata">

**Author:** ![\_4747\_1](https://avatars.discourse-cdn.com/v4/letter/_/c2a13f/32.png) [@\_4747\_1](https://community.shopify.com/u/_4747_1)\
**Post date:** [November 15, 2022, 3:31pm UTC](https://community.shopify.com/t/topic/168030/1 "2022-11-15T15:31:07Z")

</div>

お世話になります。

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

私自身はliquidの知識はまだ浅く、そもそも根本的な理解ができていない可能性があります。

私の知識では限界を感じましたので、

大変お手数なのですが、詳しい方の知恵をお借りしていと思い、投稿させていただきました。

■使用しているテーマ

有料テーマのshowcase

■現在の状態

商品詳細ページにて在庫数が表示されるようにしています。

■やりたいこと

在庫数に応じて表示内容を変更したいです。

1〜3個の場合は「残り○個です。」、4,5個の場合は「残りわずか」、それ以上の場合は在庫数を表示しないようにしたいです。

■試したこと

[https://community.shopify.com/post/1730029](https://community.shopify.com/post/1730029)

上記の方の内容をもとに下記コードを試してみましたが、在庫数5個以上の場合でも

残り在庫が表示されてしまいます。

```auto
 {% if current_variant.inventory_quantity > 3 and current_variant.inventory_management == 'shopify' %}
 残り{{ current_variant.inventory_quantity }}個です。
　{% elsif current_variant.inventory_quantity > 5 and current_variant.inventory_management == 'shopify' %}
　　残りわずかです。
 {% endif %}

```

そもそも、コードが違う可能性がありますが、ご教示いただけますと幸いです。

何卒よろしくお願い致します。

---

<div class="post-metadata">

**Author:** ![Anonymous\_44fbe07fc59d9ccaacd70575fd5a5155](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/anonymous_44fbe07fc59d9ccaacd70575fd5a5155/32/194200_2.png) [@Anonymous\_44fbe07fc59d9ccaacd70575fd5a5155](https://community.shopify.com/u/Anonymous_44fbe07fc59d9ccaacd70575fd5a5155)\
**Post date:** [November 18, 2022, 9:03am UTC](https://community.shopify.com/t/topic/168030/2 "2022-11-18T09:03:33Z")

</div>

竜也4747さま

はじめまして、フルバランスの園畑です。  
ご質問を確認いたしました。

実際に試してはいないですが、コードを見た限り「在庫が3個以上の時は個数が表示される」という処理になっているかと存じます。(current\_variant.inventory\_quantity \> 3 でコードを表示する)

```auto
if current_variant.inventory_quantity > 3

```

の部分を

```auto
if current_variant.inventory_quantity <= 3

```

に変更し、

```auto
elsif current_variant.inventory_quantity > 5

```

を

```auto
elsif current_variant.inventory_quantity <= 5

```

にされるといかがでしょうか？

ご参考になりましたでしょうか。

私たちの励みにもなりますので、 お役に立てていればBest Answerボタンを押して頂ければ嬉しいです。

分からない点があれば、またいつでもご連絡ください。

フルバランス 園畑

---

<div class="post-metadata">

**Author:** ![\_4747\_1](https://avatars.discourse-cdn.com/v4/letter/_/c2a13f/32.png) [@\_4747\_1](https://community.shopify.com/u/_4747_1)\
**Post date:** [November 23, 2022, 3:22pm UTC](https://community.shopify.com/t/topic/168030/3 "2022-11-23T15:22:06Z")

</div>

お返事遅くなってしまい大変申し訳ございません。

ご指定いただいた部分を変更させていただいたら、うまく機能いたしました。

ご回答いただきまして誠にありがとうございました。
