New Shopify Certification now available: Liquid Storefronts for Theme Developers

hide product from collection which first variant inventory is 0

Shopify Partner
3 0 3


this is my store url :

where in backpack i want to show only that product  which first inventory is not equal to 0


but still product is visible on listing page and when click to go product page other variant is selected which have inventory. 

Replies 2 (2)
Shopify Partner
255 19 28

Hello @ehsan-faramaos 

To show only the products in your Backpack store which have inventory greater than zero, you can use a filter on the "Product" model in your backpack's product controller.

Here's an example code snippet that you can add to your product controller:



public function index()
    $this->crud->addClause('where', 'inventory', '>', 0);
    return parent::index();



This code will filter out all products with an inventory of zero or less, and only display products with an inventory greater than zero.

However, keep in mind that this will only affect the products displayed on the listing page. If a customer clicks on a product that has a variant with zero inventory, they may still be able to see that variant on the product page.

To prevent this, you can modify your product page template to only display variants with inventory greater than zero. You can do this by adding an additional filter to the variant loop in your product view template:



@foreach($product->variants->where('inventory', '>', 0) as $variant)
    // display variant information here



This code will only display variants with inventory greater than zero on the product page.

I hope this helps!

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Limit Qty Purchase

Need a developer?  Just visit MageComp website
Shopify Partner
1413 131 152

Hi @ehsan-faramaos 


You have to modify the card-product.liquid to achieve this and can be done using custom code in your theme.


Let me know if you still want to implement this.

For any custom development WhatsApp or connect at Email ID: for quick consultation. | YouTube Videos
To support Buy Me a Coffee