How to hide SORT BY PRICE and PRICE FILTER NAVIGATION LAYER for not login user in magento 1.9?

magento.stackexchange https://magento.stackexchange.com/questions/108673

  •  29-09-2020
  •  | 
  •  

Question

Is it possible to hide the Sort by Price and Price Filter Navigation Layer at category product list page for users that are not logged on?

Was it helpful?

Solution 2

Thanks for Claudiu Creanga for help, I've modified his code to work perfect with my theme, i use theme puro for icotheme.

  1. hide the Sort by Price

Replace this code in template\catalog\product\list\toolbar.phtml

                                            <ul id="sort_by" class="sort_by collapse">
                                            <?php foreach ($this->getAvailableOrders() as $_key => $_order): ?>
                                                <li>
                                                    <a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__($_order) ?></a>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>

with :

                                            <ul id="sort_by" class="sort_by collapse">
                                        <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
                                            <?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): //not logged in, hide price ?>
                                                <?php if(strpos($this->__($_order), "Price") === false):  ?>
                                                <li>
                                                    <a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__($_order) ?></a>
                                                </li>
                                                <?php endif; ?>
                                            <?php else: // logged in ?>
                                                <li>
                                                    <a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__($_order) ?></a>
                                                </li>

                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                        </ul>
  1. Hide Price Filter Navigation Layer

Replace this code in template\catalog\layer\view.phtml

                    <dt><?php echo $this->__($_filter->getName()) ?></dt>
                <dd><?php echo $_filter->getHtml() ?></dd>

with:

                <?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): //not logged in, hide price ?>
                <?php if(strpos($this->__($_filter->getName()), "Price") === false):  ?>
                    <dt><?php echo $this->__($_filter->getName()) ?></dt>
                    <dd><?php echo $_filter->getHtml() ?></dd>
                <?php endif; ?>
            <?php else: // logged in ?>
                <dt><?php echo $this->__($_filter->getName()) ?></dt>
                <dd><?php echo $_filter->getHtml() ?></dd>
            <?php endif; ?>

OTHER TIPS

That filter is most likely in template\catalog\product\list\toolbar.phtml

The code that is of interest to you is:

 <select onchange="setLocation(this.value)" title="<?php echo $this->__('Sort By') ?>">
                    <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
                        <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                            <?php echo $this->__($_order) ?>
                        </option>
                    <?php endforeach; ?>
                </select>

so delete that and add something like this:

<select onchange="setLocation(this.value)" title="<?php echo $this->__('Sort By') ?>">
    <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
        <?php 
            if(!Mage::getSingleton('customer/session')->isLoggedIn()): //not logged in, hide price ?>

                <?php if(strpos($this->__($_order), "Price") === false):  ?>
                    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                        <?php echo $this->__($_order) ?>
                    </option>
                <?php else: // logged in ?>

                    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                        <?php echo $this->__($_order) ?>
                    </option>
               <?php endif; ?>
           <?php endif; ?>

    <?php endforeach; ?>
</select>

*untested code

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top