1

I want to hide price filter on some of my category pages. enter image description here

Can anyone tell me how can I achieve this?

Thanks In Advance..!

0

I think you can try using this code

app/design/frontend/YOURPACKAGE/YOURTEMPLATE>template>catalog/layer/view.phtml

  <?php if($_filter->getItemsCount()):?>
  <?php $show=1;?>
    <!-- curern filter price and currentc Cat match -->
  <?php if($_filter->getFilter()->getRequestVar()!=='price'){?>
    <?php if(Mage::registry('current_category') &&(Mage::registry('current_category')->getId()==$catId)):
    $show=0;
        endif;
     ?>
  <?php } ?>
  <!-- check show 
  <?php if($show==1){?>
  <?php echo $_filter->getHtml() ?>
  <?php } ?>
  <?php endif;?>

Or you can also refer to this link

0

Navigate to the following file

app/design/frontend/vendor/your_theme/Magento_LayeredNavigation/templates/layer/view.phtml

Add your logic around the foreach function of $block->getFilters() as shown below

<?php
    // create an array of the category ids in which you don't want the price filter
    $restricted_categories = [3, 4, 10, 14];
    $currentCategoryId = $block->getLayer()->getCurrentCategory()->getId();
?>
.....
.....
.....
<?php foreach ($block->getFilters() as $filter): ?>
    <?php
        if (in_array($currentCategoryId, $restricted_categories) && $filter->getRequestVar() == 'price') {
            continue;
        }
    ?>
    .....
    .....
    .....
<?php endforeach; ?>

Note: It seems that you are using any third party extension for Layered Navigation. If so, you have to use this code in the file of your extension.

0

You can try using following code. I have created a plugin in custom module.

app/code/Anshu/HideFilters/registration.php

<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Anshu_HideFilters',
    __DIR__
);

app/code/Anshu/HideFilters/etc/module.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Anshu_HideFilters">
        <sequence>
            <module name="Magento_Catalog" />
        </sequence>
    </module>
</config>

app/code/Anshu/HideFilters/etc/di.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Layer\FilterList">
        <plugin name="hideFilters_plugin" type="Anshu\HideFilters\Plugin\FilterPlugin" />
    </type>
</config>

app/code/Anshu/HideFilters/Plugin/FilterPlugin.php

<?php
declare(strict_types=1);

namespace Anshu\HideFilters\Plugin;

use Magento\Catalog\Model\Layer\FilterList;
use Magento\Framework\App\Request\Http;

class FilterPlugin
{
    /**
     * @var Http
     */
    private $request;

    public function __construct(
        Http $request
    ) {
        $this->request = $request;
    }

    public function afterGetFilters(FilterList $subject, $result)
    {
        $catId = $this->request->getParam('id');
        if($catId != '21') {
            return $result;
        }
        $count = 0;
        foreach ($result as $r){
            if($r->getName() == 'Price'){
                unset($result[$count]);
                return $result;
            }
            $count++;
        }
    }
}

Here I am hiding Price filter for category with ID 21.

Modify it according to your requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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