Question

How do you remove the newsletter link from the customer account navigation in Magento?

We have started using the Advanced Newsletter extension and now have two newsletter links in our customer account navigation, one for the the default newsletter and the other for the default newsletter.

I can see that the default newsletter link is added to customer account nav in app/design/frontend/base/default/layout/newsletter.xml on ln 48 with:

<customer_account>
    <!-- Mage_Newsletter -->
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="newsletter"><name>newsletter</name><path>newsletter/manage/</path><label>Newsletter Subscriptions</label></action>
    </reference>
    <remove name="left.newsletter"/>
</customer_account>

I've tried removing this link in our theme's local.xml with:

<reference name="customer_account_navigation">
    <!--<action method="removeLinkByName"><name>newsletter</name></action>-->
    <!--<remove name="newsletter"/>-->
    <action method="removeLinkByUrl"><url helper="newsletter/manage/"/></action>
</reference>

None of these methods have worked for me & I get an error when I try to remove them with an action method.

<action method="removeLinkByName"><name>newsletter</name></action> gives this error: Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName(Array

<action method="removeLinkByUrl"><url helper="newsletter/manage/"/></action> gives this error: Fatal error: Class 'Mage_Newsletter_Helper_Manage' not found in /app/Mage.php on line 546

While <remove name="newsletter"/> gives no error but does not remove the link

Was it helpful?

Solution

You need to rewrite Magento's Customer Mage_Customer_Block_Account_Navigation Block class.

create config.xml file in the app/code/local/Neo/CustomerNavigationLinks/etc

<?xml version="1.0"?>
<config>
    <modules>
        <Neo_CustomerNavigationLinks>
            <version>0.0.1</version>
        </Neo_CustomerNavigationLinks>
    </modules>
    <global>
        <blocks>
            <customer>
                <rewrite>
                    <account_navigation>Neo_CustomerNavigationLinks_Block_Account_Navigation</account_navigation>
                </rewrite>
            </customer>
        </blocks>
        <helpers>
            <customernavigationlinks>
                <class>Neo_CustomerNavigationLinks_Helper</class>
            </customernavigationlinks>
        </helpers>
    </global>
</config>

in Neo/CustomerNavigationLinks/Block/Account/ careate a file called Navigation.php with the following content in it

<?php

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

in app/etc/modules create a file called Neo_CustomerNavigationLinks.xml with the following content

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

Now in local.xml add following content

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

OTHER TIPS

In addition to Pradeep's clever solution above, I also found a good extension for allowing you to manage these links from the Magento Admin Panel

https://github.com/integer-net/RemoveCustomerAccountLinks

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