Magento 2 remove category filter from list page filters?

Magento 2 is a powerful eCommerce platform that offers a wide range of features and functionalities. One of the essential features of Magento 2 is the ability to filter products by category on the list page. However, in some cases, you may want to remove the category filter from the list page filters. In this tutorial, we’ll show you how to remove the category filter from the list page filters in Magento 2.

Step 1: Backup Your Store Before making any changes to your Magento 2 store, it is essential to create a backup of your website. This step will ensure that you have a copy of your website in case something goes wrong during the process. You can use a backup extension or manually create a backup of your store.

Step 2: Locate the Catalog Category Block The first step in removing the category filter from the list page filters is to locate the catalog category block in Magento 2. You can do this by navigating to the following path in your Magento 2 installation directory: app/code/Magento/Catalog/Block/Product/ListToolbar.php

Step 3: Override the ListToolbar.php File Once you have located the ListToolbar.php file, you can override it by creating a custom module. You can do this by following the steps below:

  1. Create a new directory in your Magento 2 installation directory and name it as “Custom”.
  2. Inside the Custom directory, create another directory named “List”.
  3. In the List directory, create another directory named “Block”.
  4. Inside the Block directory, create a new PHP file named “ListToolbar.php”.
  5. Copy the contents of the original ListToolbar.php file and paste them into your newly created ListToolbar.php file.

Step 4: Remove the Category Filter The next step is to remove the category filter from the list page filters. To do this, you need to make changes to the ListToolbar.php file that you created in the previous step. You can do this by following the steps below:

  1. Open the ListToolbar.php file in a text editor.
  2. Find the following code: $this->addColumn( ‘category_filter’, [ ‘type’ => ‘label’, ‘label’ => __(‘Category’), ‘values’ => $this->_categoryProvider->getCategoryCollection(), ] );
  3. Comment out the code by adding “//” before each line of code, as shown below: //$this->addColumn( // ‘category_filter’, // [ // ‘type’ => ‘label’, // ‘label’ => __(‘Category’), // ‘values’ => $this->_categoryProvider->getCategoryCollection(), // ] //);
  4. Save the changes to the ListToolbar.php file.

Step 5: Clear Cache The last step is to clear the cache of your Magento 2 store. You can do this by navigating to System > Cache Management and clicking on the “Flush Magento Cache” button.

Conclusion Removing the category filter from the list page filters in Magento 2 is a simple process that can be done by following the steps outlined in this tutorial. By removing the category filter, you can customize your store’s list page filters to meet your specific needs. However, it is important to note that any changes you make to your Magento 2 store should be done carefully and with a backup in place to avoid any issues.