Removing “My Orders” from Magento Customer Dashboard
As a new Magento developer looking to customize your customer dashboard, you might want to remove certain sections like the “My Orders” link. This is a common task when designing a specific user experience or applying branding changes.
Understanding the Magento Customer Account Navigation
The customer account navigation in Magento 2 is determined by the customer_account_navigation layout handle. This handle is used by the Magento_Customer module to display the links on the left sidebar of the customer dashboard.
Locating the “My Orders” Link Definition
To locate the “My Orders” link, you need to find where it’s defined in the Magento codebase. The relevant XML file is located under vendor/magento/module-customer/view/frontend/layout/customer_account.xml.
Here’s a snippet of the file that defines the “My Orders” link:
<referenceBlock name="customer-account-navigation">
<block class="Magento\Sales\BlockCustomer\Account\Link\Vieworder"
template="Magento_Sales::account/link/view.phtml">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Orders</argument>
</arguments>
</block>
</referenceBlock>
Removing the “My Orders” Link
To remove this link, you have two primary approaches:
-
Using a custom theme: Create a custom theme that extends
Magento/blankorMagento/luma. Then, override thecustomer_account.xmlfile in your theme to exclude the “My Orders” block.First, create a new XML file at
app/design/frontend/{Vendor}/{Theme}/Magento_Customer/layout/customer_account.xml.<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <remove name="customer-account-navigation.customer-account-navigation.vieworder" /> </page> -
Using a module: Develop a custom module that removes the block using an observer or layout plugin.
In your module’s
etc/frontend/di.xmlfile, add:<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\View\LayoutInterface"> <plugin name="remove_vieworder_block" type="Vendor\Module\Model\Plugin\RemoveViewOrderBlock"/> </type> </config>Then, implement the
RemoveViewOrderBlockclass to remove the block.
Best Practices and Considerations
- Always work with a local development environment when modifying Magento core files.
- Use a version control system like Git to track changes.
- Remember that removing the “My Orders” link also removes access to order history for customers. Ensure this aligns with your business requirements.
- For more advanced customizations, consider using layout plugins or observers instead of XML overrides.
Conclusion
Removing links from the Magento customer dashboard is a straightforward process once you understand the layout system and XML structure. By following these steps, you can easily remove the “My Orders” link and create a tailored experience for your customers.
Remember that Magento provides extensive documentation on its layout and block systems. If you need further guidance on customizing layouts or developing modules, consider checking out our resources at LaravelCompany.