Magento 2 categories group your products under different conditions: men products, bottoms, gear, sport, etc. However, sometimes you need to hide categories in Magento in case they are empty to avoid 404 issues and provide a seamless customer experience.

Unfortunately, there is no option for that in default Magento. But you can always rely on the Magento 2 Dynamic Categories extension to do the job.

To hide empty categories in Magento:

  1. Navigate to Catalog > Categories and select the category you want to enable a corresponding option for.
  2. Unfold the Dynamic Category section and enable the Automatically Disable Categories Without Products option.

Hide Empty Categories in Magento

Once you enable an option to hide empty categories in Magento, the cron which runs every day at 1 a.m. will check if there are products in the categories.

If there are no products there, the category will be disabled and you will receive the following notification to your admin panel:

Disabled Category Notification

But what will happen with the category page, won't it lead to the 404 error? - this is a great question to ask.

Dynamic Category Extension got you covered. It creates 301 redirects for disabled categories by default.

If the category is disabled the extension checks whether this category has some active parent category and redirects customers to it and displays the following notification:

Disabled Category Redirect Notification

In case there are no parent categories, your customers will be redirected to the homepage automatically.

So you see, to hide empty categories in Magento and cover the redirects you only need to enable one option. There is no need to go and check whether all categories have products assigned to them in order to disable them and created a redirect. You just need Dynamic Categories to do that for you.