Sold out button should display when product inventory stock below 7 in product grid layout

Hello,

Currently i am using empire theme. I have changed code for sold out condition that if product inverntory stock is below 7 than user not allows to add to cart. sold out button will display there instead of add to cart.

So this functionality working fine in Product detail page. but i need to do this same functionality while product is in grid layout (product-grid-item.liquid)

https://supplementxpress.com/search?type=article%2Cpage%2Cproduct&q=APS*+Tribulus*+1500*

Here i have searched product for “APS Tribulus 1500” which is below 7 in stock but it allows to add to cart, that should not happen. i want to show sold out there.

I have attached file as well.

Can someone please help me on this asap.

Thank you !

Hi @Krishna12 ,

Please add code here:

Code:

{% if product.selected_or_first_available_variant.inventory_quantity < 7 %}
          {% assign quick_buy_text = 'product.buttons.sold_out' | t %}
          {% assign quick_buy_classes = quick_buy_classes | append: ' disabled' %}
{% endif %}

Hope it helps!

Code is working. Thank you for your help