Hello Magento Friends,

Today we will learn How to Add Stock Filter on Category Layered Navigation in Magento 2.

Providing a seamless and efficient shopping experience to customers is paramount. One way to achieve this is by enabling useful filters that help customers narrow down their product searches.

Check out

Adding a stock filter to the category layered navigation in Magento 2 can greatly enhance the user experience by allowing customers to filter products based on their availability. Providing such filtering options can contribute to a more streamlined and customer-friendly shopping experience on your Magento 2 e-commerce platform.

In this tutorial, we will guide you through the process of adding a stock filter to the category layered navigation in your Magento 2 store.

Steps to Add Stock Filter on Category Layered Navigation in Magento 2:

Step 1: First, we need to create a “di.xml” file inside the extension at the following path.

app\code\Vendor\Extension\etc\frontend

Then add the code as below

Step 2: After that, we need to create a “Stock.php” file inside the extension at the following path.

app\code\Vendor\Extension\Model\Layer\Filter

Now add the code as mentioned below

Step 3: After that, we need to create the “FilterList.php” file inside the extension at the following path.

app\code\Vendor\Extension\Model\Plugin

And finally, add the code as follows

Step 4: Once all files are created in your Magento, you need to run Magento upgrade, compile and deploy commands as follows.

Output:

Visit your Magento 2 store’s category page, and you should now see the stock filter in the layered navigation.

Stock filter

Now if the customer selects the In Stock option in the Stock filter menu, it will show the products that are available for purchase.

In stock option selected in stock filter

And if the customer selects the Out of Stock option, it will show the products that are currently not in stock.

Out of stock option selected in stock filter

Conclusion:

By following these steps, you can enhance the user experience of your Magento 2 store by adding a stock filter to the category layered navigation. This will enable customers to filter products based on their availability, helping them find products currently in or out of stock.

If you face any errors while adding a stock filter on category layered navigation, drop a comment here, and I will quickly provide you with the appropriate solution.

Share the tutorial to add stock filters in Magento 2 with your friends, and stay tuned for more such content.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]