What's up guys, I'm looking for how to remove links on "My Account" page in magento 2 with PHP code.

So i've searched a lot and only saw this layout xml solution:
How to add/remove links on my account navigation magento2?
But what i want is do it by PHP code, because i have some special condition, for example, when customer is in wholesale group, then the "My order" is hiding.

The check customer part is an easy part and i've done it, but not with the "hiding my order" part
Any idea? Please help, thanks :) enter image description here enter image description here

  • you can remove whole sidebar and create custom sidebar then after you can do whatever you want. Commented Oct 5, 2018 at 11:31
  • you can try plugin
    – kunj
    Commented Oct 5, 2018 at 12:28
  • @AasimGoriya that sound cool but won't be the best practice :) I hope to find another way :)
    – fudu
    Commented Oct 5, 2018 at 13:12

2 Answers 2


You can try this:

create this file Vendor/Module/etc/frontend/di.xml with below content.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Framework\View\Element\Html\Links">
        <plugin name="vendor_module_element_link" type="\Vendor\Module\Plugin\LinksPlugin" sortOrder="1" />

Create LinksPlugin.php file in /Vendor/Module/Plugin/ with below cpntent.

namespace Vendor\Module\Plugin;

class LinksPlugin
    public function afterRenderLink(\Magento\Framework\View\Element\Html\Links $subject, $result, \Magento\Framework\View\Element\AbstractBlock $link)
            $result = "";
        return $result;

  • wow, thanks, i'll try this and feedback to you later :)
    – fudu
    Commented Oct 5, 2018 at 13:11

You can create observer for event layout_render_before_customer_account and add logic that necessary to your requirements.

Example how to create Observer located here https://magento.stackexchange.com/a/228406/43911

  • thanks for replying, but if i use observer, then how to hide the "My Order" (which is the links that i want to hiding)?
    – fudu
    Commented Oct 5, 2018 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.