Mini Tutorial:
Removing Customer Account Navigation Links via Layout XML

Every Magento client we’ve worked with, has unique needs and requirements for the customers that use their site. Magento has a big and expansive library of features to fit many of our merchant’s needs but that doesn’t mean that retailers need to execute every feature available in order to provide great customer experience. If we kept all the unnecessary features enabled, it could create a frustrating experience for site users as some features might not do anything. One great example is the customer account navigation menu.

2014-05-06-081832_208x360_scrot
Quite a few customer account navigation links can be turned off easily from the Magento backend by turing off their respective features, but quite a few of these are also hardcoded in Magento through the Magento Core layout XML file. As it is best practice to make layout modifications when possible by using layout XML, I will show you how to remove a few of these links by implementing a layout XML method to remove them via a class rewrite. As an example of a link we’re going to remove, let’s take a look at the Recurring Profiles link in that list.

That link is added with this layout XML declaration in app/design/frontend/base/default/layout/sales/recurring_profile.xml:

<customer_account>
<reference name="customer_account_navigation" >
<action method="addLink" translate="label">
<name>recurring_profiles</name>
<path>sales/recurring_profile/</path>
<label>Recurring Profiles</label>
</action>
</reference>
</customer_account>

This is quite fine as usually there are remove versions of the methods to add things through XML, but when inspecting the block element in use for adding that link (Mage_Customer_Block_Account_Navigation), there is no opposing removeLink for the addLink method. This is where we’re going to start doing our work.

#1. House Our Rewrite in a Module

First things first, we need to house our rewrite in a module. If you have a preexisting module you want to add this to, you can skip creating the app/etc/modules/Acme_Module.xml file.

Create app/etc/modules/Acme_Module.xml. This will tell Magento about our new Module that houses our rewritten class.

<?xml version="1.0"?>
<config>
<modules>
<Acme_Module>
<active>true</active>
<codePool>local</codePool>
</Acme_Module>
</modules>
</config>

#2. Create our app/code/local/Acme/Module/etc/config.xml

By creating our app/code/local/Acme/Module/etc/config.xml, this file will tell Magento where to find our rewritten class.

<?xml version="1.0"?>
<config>
<modules>
<Acme_Module>
<version>0.0.1</version>
</Acme_Module>
</modules>
<global>
<blocks>
<customer>
<rewrite>
<account_navigation>Acme_Module_Block_Account_Navigation</account_navigation>
</rewrite>
</customer>
</blocks>
</global>
</config>

#3. Install app/code/local/Acme/Module/Block/Account/Navigation.php

Now, for our class that adds our layout XML method. Install this in app/code/local/Acme/Module/Block/Account/Navigation.php:

<?php
class Demac_Customer_Block_Account_Navigation
extends Mage_Customer_Block_Account_Navigation
{
public function removeLinkByName($name)
{
unset($this->_links[$name]);
return $this;
}
}

#4. REMOVE LINK WITH LOCAL.XML

After that’s all done, we can add this to our local.xml:

<customer_account>
<reference name="customer_account_navigation">
<action method="removeLinkByName">
<name>recurring_profiles</name>
</action>
</reference>
</customer_account>

The name argument can be determined by finding the name as described in the original XML files where addLink was called.

That’s all folks!