Magento: How to Hide Empty Category

how to hide empty category

When a product is out of stock, displaying empty categories will only irritate customers so it’s better to hide category from Top menu for which you don’t have products to show to your customers. As a store owner, you might want to hide or disable an empty category because either the product is out of stock or discontinued. The category will automatically become visible when it gets active products. Disabling a category means that the category will not appear on the front end in any way (not site search, not category listings).  If a customer somehow has the direct page URL (like via Pinterest link) they will receive a 404 Page not found error page.

To hide an empty category from Top menu, do the following:

Go to app/code/core/Mage/Catalog/Block Folder and copy Navigation.php. Override Navigation.php in your local package.
Open Navigation.php of your package and paste the following code in this file:

if ($category->getIsActive()) {

$cat = Mage::getModel('catalog/category')->load($category->getId());

$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cat);

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);

Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);

if(count($products)==0)

return;

}

3 thoughts on “Magento: How to Hide Empty Category

Leave a Reply

Your email address will not be published. Required fields are marked *