Hello Magento Friends,

The subject matter of today’s Magento technical solution is How to Disable Empty Category Programmatically using Root Script in Magento 2?

Categories in Magento 2 help to sort products. Categories help customers to find products easily. But if you have an empty category, it will show an empty page to the customer, which will affect the store’s customer experience. Hence, store owners must disable or delete empty categories from the storefront.

Categories can be disabled from the Magento 2 admin panel. Alternatively, you can disable categories programmatically also.

Let’s find out how to disable empty categories programmatically using the root script in Magento 2.

Steps to Disable Empty Category Programmatically using Root Script in Magento 2:

Category position before running the script

before

Step 1: Create a file in your Magento root directory at the below path. 

magento_root_directory\Disablecategory.php

Then add the code as below

Step 2: After the above step, you will need to run the below-given URL.

https://yourdomain.com/Disablecategory.php 

Category position after running the script

after

Conclusion:

Hopefully, you were able to disable the empty category programmatically in Magento 2. You can also change the position of the category programmatically in Magento 2.

Share the tutorial with your Magento friends and stay updated for more Magento tutorial guides.

Happy Coding!

Click to rate this post!
[Total: 1 Average: 5]