Remove Navigation Links from Account Panel

When add a navigation link, we could use addLink method. How about removeLinkByName method? Convenient.

Posted on March 30, 2016 in Magento

I have developed multiple ecommerce websites for different clients. They all have their own requirement for customer account navigation links. So I ended up writing a small module to do it:


#app\etc\modules\Jeff_Customerlinks.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
       <Jeff_Customerlinks>
          <active>true</active>
          <codePool>local</codePool>
       </Jeff_Customerlinks>
    </modules>
</config> 

Block File:


#app\code\local\Jeff\Customerlinks\Block\Account\Navigation.php

class Jeff_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {
    public function removeLinkByName($name) {
        unset($this->_links[$name]);
    }
}

Config.xml file:


#config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <blocks>
            <customer>
                 <rewrite>
                      <account_navigation>Jeff_Customerlinks_Block_Account_Navigation</account_navigation>
                 </rewrite>
            </customer>
        </blocks>
    </global>
</config>

After that you can simply make the changes through local.xml:


#local.xml
<customer_account>
    <reference name="customer_account_navigation">
        <action method="removeLinkByName">
           <name>recurring_profiles</name>
        </action>
        <action method="removeLinkByName">
           <name>billing_agreements</name>
        </action>
        <action method="removeLinkByName">
           <name>reviews</name>
        </action>
        <action method="removeLinkByName">
           <name>downloadable_products</name>
        </action>
        <action method="removeLinkByName">
           <name>OAuth Customer Tokens</name>
        </action>
    </reference>
</customer_account>


comments powered by Disqus