Solved

Removing Quantity Selector on Cart page when current_variant.inventory_quantity is equal to 1.

dhsk11
Tourist
7 2 3

I wanted to know how to remove the quantity selector on cart page when I have one product in the inventory available. If there is more than one product in the inventory, I want the quantity selector to show.  I believe I need to edit this part of the code:

<td data-quantity data-label="{{ 'cart.label.quantity' | t }}">
              {% if current_variant.inventory_quantity == 1 %}
              <div>NONE</div>
              {% else %}              
              <div class="flex  items-center hidden lg:block">
                <button
                  type="submit"
                  class="w-6 p-1 align-middle"
                  @Click.prevent="qtyAdjust($event, -1, 'quantity_{{ item.key | replace: ':', '' }}')"
                  :aria-label="'{{ 'general.accessibility.decrement_one' | t }} ' + '{{ item.title }}'">
                  {% render 'icon-minus' %}
                </button>
                <input type="text"
                  name="updates[]"
                  id="updates_{{ item.key }}"
                  value="{{ item.quantity }}"
                  class="min-w-0 w-6 pb-1 text-center text-sm lg:text-base border-b-text border-current bg-transparent"
                  min="0"
                  aria-label="{{ 'cart.label.quantity' | t }}"
                  pattern="[0-9]*"
                  x-model.number="quantity_{{ item.key | replace: ':', '' }}"
                  autocomplete="off" />
                <button
                  type="submit"
                  class="w-6 p-1 align-middle"
                  @Click.prevent="qtyAdjust($event, 1, 'quantity_{{ item.key | replace: ':', '' }}')"
                  :aria-label="'{{ 'general.accessibility.increment_one' | t }} ' + '{{ item.title }}'">
                {% render 'icon-plus' %}
                </button>
              </div>
              {% endif %}
            </td>

I added 

{% if current_variant.inventory_quantity == 1 %}
<div>NONE</div>
{% else %} 

but it is not working. 

cart.png

Thanks for your help!

Accepted Solution (1)

IttantaTech
Shopify Partner
525 55 102

This is an accepted solution.

Hello, @dhsk11 

Use 

{% if item.variant.inventory_quantity == 1 %} 

 

 

Instead of

{% if current_variant.inventory_quantity == 1 %}

Thanks,
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at info@ittanta.com

View solution in original post

Replies 2 (2)

IttantaTech
Shopify Partner
525 55 102

This is an accepted solution.

Hello, @dhsk11 

Use 

{% if item.variant.inventory_quantity == 1 %} 

 

 

Instead of

{% if current_variant.inventory_quantity == 1 %}

Thanks,
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at info@ittanta.com
dhsk11
Tourist
7 2 3

Thank you very much! That worked perfectly.