0

I want to hide the price side bar if the customer is not logged in on the product category list page.

0

Copy view.phtml file from

vendor/magento/theme-frontend-luma/Magento_LayeredNavigation/templates/layer/view.phtml

and override it in your theme.

Add below code just before

<div data-role="collapsible" class="filter-options-item">

<?php if($filter->getName() == 'Price'){
    if ($helper->isLoggedIn() == false) {
        continue;
    }
} ?>

Add below isLoggedIn function to in your custom module helper with constructor argument.

public function __construct(
            Context $context,
            \Magento\Framework\App\Http\Context $httpContext
    ) {
        parent::__construct($context);
        $this->httpContext = $httpContext;

    }

public function isLoggedIn()
    {


        $isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);

        return $isLoggedIn;
    }

Now price filter only showing for login customer.

Let me know if you have any issue/concern from above.

0
0

check loggedIn user

<?php


$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
//echo $isLoggedIn;

if ($isLoggedIn == 1){
?>

<?php $_menu = $block->getHtml(0, 'level-top', 'submenu'); ?>
<div class="mb-navigation vertical-menu d-none d-md-block">
    <div class="title"><span class="mbi mbi-menu"></span><span class="d-none d-md-block"><?= __("Categories") ?>
            <i class="mbi mbi-ios-arrow-down"></i></span></div>
    <div class="navigation" data-action="navigation">
        <ul class="smartmenu magebig-nav">
            <?= /* @escapeNotVerified */ $_menu; ?>
            <?= /* @escapeNotVerified */ $block->getChildHtml(); ?>
        </ul>
    </div>
</div>
<?php
}
?>

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.