简体   繁体   中英

How can I remove the “Checkout” url from top links in Magento?

I'm using Magento 1.7 (latest version) and I want to remove the "Checkout" link only from the top navigation link.

I have tried

<remove name="checkout_cart_link" />

but it removes the cart link too, which I dont want to remove.

Old post, but for others searching you don't want to be copying and editing checkout.xml and want to avoid adding custom code.

To do this via local.xml , remove the block like the asker tried, then add the cart link back in (the name of the new block is slightly different).

        <reference name="top.links">
            <remove name="checkout_cart_link" />
            <block type="checkout/links" name="checkout_cart_link_custom">
                <action method="addCartLink"></action>
            </block>
        </reference>

Credit to this post which gave the idea of removing and adding back in: http://www.classyllama.com/development/magento-development/editing-magentos-top-links-the-better-way

Direct checkout.xml on never update avoide changes on core files

<reference name="top.links">
            <block type="checkout/links" name="checkout_cart_link">
                <action method="addCartLink"></action>
                <action method="addCheckoutLink"></action>
            </block>
</reference>

comment this code or remove

<!--<action method="addCheckoutLink">< /action>-->

Using Local.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="top.links">
          <remove name="checkout_cart_link"/>
            <block type="checkout/links" name="checkout_cart_link_custom">
                <action method="addCartLink"></action>
                <!--<action method="addCheckoutLink"></action>-->
            </block>
        </reference>
    </default>
</layout> 

OR

<?xml version="1.0"?>
 <layout version="0.1.0">
    <default>
    <reference name="top.links">
            <remove name="checkout_cart_link" />
            <block type="checkout/links" name="checkout_cart_link_custom">
                <action method="addCartLink"></action>
            </block>
          </reference>
        </default>
    </layout> 

The top links are done a bit differently to other things, rather than each link being a block you can remove in itself, there is one parent block named top.links which contains all of the links, and in one case there is a child block as you have found named checkout_cart_link which contains the links for the checkout and cart.

Links are added into the top.links by calls to block methods in your layout files and this is done across a number of different layout files. The block method called on the top.links block is addLink() and you can find this method in class Mage_Page_Block_Template_Links . The child block checkout_cart_links also defines 2 more block methods addCartLink() and addCheckoutLink() which can be found in class Mage_Checkout_Block_Links .

Unfortunately removing already added links is one of only a few things you can't do by default from your own layout file as there is no removeLink() or similar block method. This means that to remove the checkout link, you have a couple of choices

  • Add your own removeCheckoutLink() block method into a block you create and reference it from your own layout file. This would need to reverse what the addCheckoutLink() block method did. Note that a local.xml layout file, and layout files you define in your own module will affect the layout after all core modules, so you could be sure your method would run after the addCheckoutLink() method

  • The other easier option, but one that leaves the standard checkout layout file edited is to copy the checkout.xml layout file into your current theme layout folder if it isn't already there and remove the addCheckoutLink() action node inside the checkout_cart_link block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM