1

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.

2 Answers 2

1

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();

?>
6
  • Is there any other way to disable category in navigation without changing is_active status? I just want to hide category with some conditions like customer group. Mar 23, 2017 at 10:24
  • One more question. Do you know which event will be evoked when top menu is rendering? Mar 23, 2017 at 10:45
  • there are two events for category collection. 1. _load_before 2. _load_after Mar 23, 2017 at 10:53
  • This code doesn't make a category disable. doesn't work for me Aug 7, 2019 at 9:29
  • @VinitKumar Check in the admin if this code makes your category inactive or not. Aug 8, 2019 at 7:29
0

First, create a custom attribute for categories like "show for customer [group]" with yes-no field then you can make use of plugin/interceptor in Magento to achieve this. In the plugin, check the current customer group and filter the categories that are enabled with the custom attribute you just created.

In this way, you can achieve your requirement. I think this is an ideal way to achieve this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.