How to use Else in this code

PamDigital
Explorer
57 2 9

Hey there,

 I want to add else on this code. This codes shows a text when my product's inventory in under 5. If it is above of 5 I want to show another text. Can someone help me with it please?

 

 {% if enable_hot_stock and product.variants.size > 0 and product.variants.first.title != 'Default Title' %}
                    {% assign max_stock = section.settings.number_stock | plus: 0 %}
                    <div class="hot_stock" data-stock-hot data-value="{{max_stock}}">
                        {% if current_variant.inventory_management %}
                            {% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= max_stock %}
                            {{ "products.product.stock_hot" | t | replace: '[inventory]', current_variant.inventory_quantity }}
                            {% endif %}
                        {% endif %}
                    </div>
                    {% endif %}

 

  

0 Likes
Ninthony
Shopify Partner
1966 296 780

You should use another if statement inside of that one, because 5 is greater than 0 so that's going to valuate to true assuming it's less than or equal to the max stock. I think anyway, that's how it's working out in my head:

{% if enable_hot_stock and product.variants.size > 0 and product.variants.first.title != 'Default Title' %}
{% assign max_stock = section.settings.number_stock | plus: 0 %}
<div class="hot_stock" data-stock-hot data-value="{{max_stock}}">
    {% if current_variant.inventory_management %}
        {% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= max_stock %}
            {% if current_variant.inventory_quantity > 5 %}
              //Whatever message you want to put here
            {% else %}
              {{ "products.product.stock_hot" | t | replace: '[inventory]', current_variant.inventory_quantity }}
            {% endif %}
        {% endif %}
    {% endif %}
</div>
{% endif %}

 

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
PamDigital
Explorer
57 2 9

Hey @Ninthony  Thanks for your answer! I tried the same code actually.  The code after 'else' is working fine but, before the 'else' is not working. I don't really know why. Here is my code;


 

{% if enable_hot_stock and product.variants.size > 0 and product.variants.first.title != 'Default Title' %}
{% assign max_stock = section.settings.number_stock | plus: 0 %}
<div class="hot_stock" data-stock-hot data-value="{{max_stock}}">
    {% if current_variant.inventory_management %}
        {% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= max_stock %}
            {% if current_variant.inventory_quantity > 5 %}
              <span class="pam-qty"><span class="pam-qty-msg">Sınırlı Stok! </span></span>
            {% else %}
              {{ "products.product.stock_hot" | t | replace: '[inventory]', current_variant.inventory_quantity }}
            {% endif %}
        {% endif %}
    {% endif %}
</div>
{% endif %}

 

0 Likes