Learn in this tutorial how to hide any link on the “my account” page of WooCommerce with a simple code snippet.
When you install and configure WooCommerce, a page is created that allows the customer to manage their orders, personal data, etc. By default it has the following sections:
- Dashboard
- Payment methods (if any)
- Orders
- Downloads
- Addresses
- Account Details
- Logout
Depending on the project you may want to hide some of them. In fact, the other day a subscriber asked me how he could leave only the “Account Details” section.
Are you also interested in hiding some particular links?
Thanks to the woocommerce_account_menu_items
filter in WooCommerce you can do it easily.
Here’s how to do it:
Snippet to hide links from the my WooCommerce account page.
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case you use the woocommerce_account_menu_items
filter to remove the fields you don’t want to be displayed, leaving only the “Account details” visible.
Here’s the list of WooCommerce default fields and how to remove them so you can customize the snippet above to your liking:
unset( $menu_links['edit-address'] ); // Addresses.
unset( $menu_links['dashboard'] ); // Desktop
unset( $menu_links['payment-methods'] ); // Payment methods
unset( $menu_links['orders'] ); // Orders
unset( $menu_links['downloads'] ); // Downloads
unset( $menu_links['edit-account'] ); // Account details
unset( $menu_links['customer-logout'] ); // Logout
If for some reason you prefer to simply hide the links using CSS you can add this snippet to the end of the style.css file:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case, you would be hiding all the links, but you can remove the lines that you do want to display.
Conclusion
As you can see, with a few lines of code you can hide the field you want on the my WooCommerce account page.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉