16

I am running Mage 1.5.0.1 and I am trying to remove the navigation links from the My Account section.

My local.xml has the following which works fine:

 <customer_account>
    <reference name="root">
        <action method="setTemplate"><template>page/staticpage.phtml</template></action>
    </reference>
   <reference name="left">
        <remove name="cart_sidebar" /> 
        <remove name="catalog.compare.sidebar" />   
    </reference>
 </customer_account>

When I try to add the following code the system throws and error:

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

Error

Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName

I saw this function in 1.4, is it not supported anymore or am I doing something wrong?

Chris
  • 1,400
  • 9
  • 20
  • 35
  • 2
    You can also use this free and easy 'plug and play' extension: http://www.magentocommerce.com/magento-connect/manage-customer-navigation-menu.html – Gerard de Visser Sep 25 '14 at 12:45

11 Answers11

42

I had a similar problem, and I didn't want to comment out addLink node because we want to implement our changes in local.xml only. Ended up writing a small module to do it:

app\etc\modules\Stackoverflow_Customerlinks.xml:

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

app\code\local\Stackoverflow\Customerlinks\Block\Account\Navigation.php:

<?php

class Stackoverflow_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {

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

}

app\code\local\Stackoverflow\Customerlinks\etc\config.xml:

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

After that, you can simply make the changes through 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>
    </reference>
</customer_account>

Have fun :)

Daniel Sloof
  • 12,568
  • 14
  • 72
  • 106
  • Huh - came up with same solution independently... or, close anyhow. Wierdly - i cant seem to remove the "reward points" links. Cant seem to figure out its proper name to target, maybe? Can't seem to find where it gets added in the first place (looked through sale.xml reward.xml ... ) any thoughts? – Bosworth99 Jun 13 '12 at 16:11
  • 2
    'enterprise_reward' if anyone is interested... – Bosworth99 Jun 13 '12 at 16:20
  • I beg you ,can you PLEASE specify Where to put `local.xml` ? Thanks – Pratik Joshi Nov 07 '14 at 10:50
  • @jQueryAngryBird app/design/frontend///layout/local.xml – Daniel Sloof Nov 07 '14 at 14:24
  • @DanielSloof , hi Why dont u think `lvekua` gave better answer? – Pratik Joshi Nov 07 '14 at 15:06
  • @jQueryAngryBird he adds logic to a template, things like these should be solved via layout XML. However silentbang's solution is definitely acceptable (and for some people preferable) as well. The downside to that solution is that you need to manually add links that you want, instead of removing those that you don't want. – Daniel Sloof Nov 07 '14 at 15:25
  • Ok now check here http://stackoverflow.com/questions/1977824/magento-how-to-add-remove-links-on-my-account-navigation `Ryan Christofferson` gave amazing answer , anything u want to say ? downside? – Pratik Joshi Nov 07 '14 at 15:29
  • Don't forget to disable or flush cache :-) – Anthony Jan 16 '15 at 18:39
16

By default, we don't have such method as "removeLink". Therefore, the trick is to remove the whole block using "unsetChild" approach and add the needed links block back with our own links added to it in local.xml

<customer_account translate="label">
        <reference name="left">
            <!--Unset the whole block then add back later-->
            <action method="unsetChild"><name>customer_account_navigation</name></action>
            <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
                <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
                <action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
                <action method="addLink" translate="label" module="review"><name>reviews</name><path>review/customer</path><label>My Product Reviews</label></action>
                <action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Favorite</label></action>
                <action method="addLink" translate="label" module="newsletter"><name>newsletter</name><path>newsletter/manage/</path><label>Newsletter Subscriptions</label></action>
            </block>
            <remove name="catalog.compare.sidebar"/>
        </reference>
    </customer_account>
Duc Tran
  • 6,016
  • 4
  • 34
  • 42
  • 2
    Great solution, this feels like the `Magento` way to do this. Also worth mentioning that modules may add their own links, so they would also need to be addressed separately. – Jongosi May 27 '14 at 10:32
  • Definitely a +1 for me as it avoids a rewrite, and this is probably how I would have done it these days (my answer is 3 years old). A small downside is that you need to add all the links that you want yourself, instead of removing the ones that you don't. Also it's a mystery why Magento removed the removeLinkByName method at some point. – Daniel Sloof Nov 07 '14 at 15:28
  • Neat solution, didnt came on this. Good job! – MageZeus Dec 10 '14 at 09:25
  • Great solution! When I drop this in, however, it leads to a duplicate My Account menu. The links in both are the same and correct, there are just two of them. – Michael Thompson Apr 15 '15 at 13:57
8

Just to inform you guys about all the links in the navigation menu. To remove all links in local.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
    <customer_account>
        <reference name="customer_account_navigation" >
                <!-- remove the link using your custom method -->
                <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>

                <action method="removeLinkByName"><name>account</name></action>
                <action method="removeLinkByName"><name>account_edit</name></action>
                <action method="removeLinkByName"><name>address_book</name></action>
                <action method="removeLinkByName"><name>orders</name></action>
                <action method="removeLinkByName"><name>tags</name></action>
                <action method="removeLinkByName"><name>wishlist</name></action>
                <action method="removeLinkByName"><name>newsletter</name></action>

        </reference>
    </customer_account>
</layout>

Thanks for your answer Daniel Sloof

Martijn van Hoof
  • 740
  • 10
  • 28
7

You can use that:

    <customer_account>
        <action method="unsetChild"><name>customer_account_navigation</name></action>
            <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
...
            </block>
     </customer_account>

Rewriting is not solution...

Ronan
  • 79
  • 1
  • 1
2

I just refactored account dashboard links and removed CSS nth-child selectors as I had before and instead changed app/design/frontend/default/your_theme/template/customer/account/navigation.phtml to this

<div class="block block-account">
<div class="block-title">
    <strong><span><?php echo $this->__('My Account'); ?></span></strong>
</div>
<div class="block-content">
    <ul>
        <?php $_links = $this->getLinks(); ?>
        <?php $_index = 1; ?>


            <?php $_count = count($_links); 
                unset($_links['recurring_profiles']); 
                unset($_links['billing_agreements']); 
                unset($_links['reviews']);
                unset($_links['tags']);
                unset($_links['OAuth Customer Tokens']);
                unset($_links['downloadable_products']); 
            ?>


        <?php foreach ($_links as $_link): ?>
            <?php $_last = ($_index++ >= $_count); ?>
            <?php if ($this->isActive($_link)): ?>
                <li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
            <?php else: ?>
                <li<?php echo ($_last ? ' class="last"' : '') ?>><a href="<?php echo $_link->getUrl() ?>"><?php echo $_link->getLabel() ?></a></li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
</div>

basically unset any unwanted links.

lvekua
  • 196
  • 5
  • 17
1

There are other various xml file that refer to <reference name="customer_account_navigation"> where you can copy the xml file to your layout directory and comment out the addLink node other than that, I see a removeLinkByUrl that you might try instead.

dan.codes
  • 3,523
  • 9
  • 45
  • 59
0

You can also, override declaration by empty link - without define 'path' and 'label', direcly in local.xml:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink"><name>tags</name></action>
        <action method="addLink"><name>newsletter</name></action>
    </reference>
</customer_account>
0

Go to app/design/frontend/YourPackageName/YourThemeName/layout/, create a sales/ directory if there isn't one, and create an empty file or directory named billing_agreement.xml and recurring_profile.xml.

Cleanest method ever, no custom functions, no CSS hacking, no logic in template files.

This completely hides the Billing Agreements and Recurring Profiles features from the user.

Phil
  • 1,288
  • 1
  • 10
  • 19
0

This module makes functionality ordering or show the links of my own, does not make for layout and phtml overwrites the block and makes all the logic there.

http://www.magentocommerce.com/magento-connect/customer-navigation.html

  • The cleanest solution would be to make an overwrite of the box and add a method to remove links from layout.
jruzafa
  • 4,156
  • 1
  • 24
  • 26
-1

My Account Navigation links comes from customer.xml file.

            <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
                <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
            </block>
Swapna Taru
  • 688
  • 5
  • 6
-1

My apperoach is to bring power of css and avoid hevy code modifications.

E.G.

/* CUSTOMER ACCOUNT LEFT NAV DISABLER */
.block-content li:nth-child(4),
.block-content li:nth-child(5),
.block-content li:nth-child(6),
.block-content li:nth-child(8){display: none;}

Obviously change selectors to your themes customer navigation li, and use li:nth-child() sudo with number between parenthesis which you want to remove. Use comments in customer.xml as well just in case u don't forget what you did 6 month down the line.

Pragnesh Chauhan
  • 8,363
  • 9
  • 42
  • 53
lvekua
  • 196
  • 5
  • 17
  • 3
    this is extreme bad practice! faking it away with css is no solution! – Michael Leiss Jun 21 '13 at 10:55
  • There is no faking in it. I think its a very clean solution as compared to tinkering with XML or PHP. – Ashfame Jun 21 '13 at 19:31
  • 2
    this is in no way a thing any webdeveloper should do. -maybe links lead to bad pages and can be crawled by robots -its redundant markup and css code -there are better solutions (layout.xml/block methods) -you have hardcoded child ids, which is simply nonsense -you have actually no clue what you are talking about, when you call this a "clean solution" – Michael Leiss Jun 22 '13 at 21:08
  • I hate to say this - because this is an ugly solution, but while all the XML answers didn't work for me, this worked for sure. If you specify the css so it only applies to the account box, then it is ok. By the way, google shouldn't even get to indexing a registered user's acount page. Also a user will not tell the difference if a list item is hidden by CSS or not even rendered out in the first place. – Lajos Mészáros Nov 24 '13 at 08:42
  • This is a bad idea. For users with slow or unstable connections, if the page HTML is loaded before the stylesheet is loaded, the links to be removed will be temporarily visible. – Phil Mar 04 '14 at 07:51