Magento – How to disable category in magento 2 programmatically

category-productsmagento-2.1navigation

I would like to disable category from navigation bar under some conditions like for certain customer groups I would like to show certain categories. Is there any way to do that and how can I do that.

Best Answer

You can disable the category with this code.

<?php 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category_id = 'your_category_id';
$collection = $objectManager ->get('Magento\Catalog\Model\Category')->load($category_id);
$collection->setData('is_active', 0);
$collection->save();

?>
Related Topic