
Hello guys, in the last tutorial, we learned about how to add a menu item to my account but in this today’s tutorial, we will learn how we can remove any menu item from the My Account page in woocommerce.
My Account page as you know is the customer’s dashboard view to see their order details, edit the address, check payment method details, etc. On this page, we will make customization to remove menu items.
So well, we will use the Astra WordPress theme also for this tutorial for customization and show you practically. The theme doesn’t matter you can use any theme like Divi, Ultra, Shoppe, Avada, etc.
To see the My Account page you have to log in and navigate to the “My Account” menu from the header menu or you can type in the URL like “https://yoursite.com/my-account”.
The above image is the default look of the My Account page in the Astra theme. You can modify it as you want.
Let’s start to remove a menu item from the My Account page in woocommerce.
Remove Menu Item in My Account Page
To remove the menu item from my account page, first, we will make a function and then use the woocommerce filter hook on that function.
In that function, we will unset the specific menu item which we want to remove. Then that filter hook will tell WordPress to render the menu item as per function return.
See Also: WooCommerce Remove Update Cart Button and Update Automatically
Let’s see how you can use a filter hook and trigger the function on it.
Remove Menu Link
To remove a menu item link from my account page on woocommerce website, you have to use the woocommerce_account_menu_items
filter hook. You can remove any of the menu links, you just have to give the correct endpoint in the unset() function.
Let’s take an example, you want to remove the “Download” menu because you are not selling any Downloadable products on your woocommerce store. To remove the Download menu link from the My Account page, see the following code reference.
Save the above code in your child theme’s functions.php file. If you don’t have a child theme check out the detailed guide on how to create a WordPress child theme.
After saving the above code in the functions.php file, you will see the Download menu disappear from the My Account page. See the following image for reference.
But in case you want to remove any other menu items from the My Account page then see the following reference endpoints for them.
Other Menu’s Endpoints
But removing the menu links from the My Account page using the unset() function is not the final step yet. Because you just unset the menu link from $menu_links
array. When you go to the /downloads page it will show you the Download page which should not happen.
Remove Menu Endpoint
So to remove both menu links and its pages as well, you have to clear the endpoint from the WooCommerce > Settings > Advanced under the Account endpoints section.
After clearing the endpoint, when you hit the /downloads in the URL, it will show you a 404-error page.
Conclusion
So in this tutorial, you have learned about the My Account page menu in woocommerce and how you can remove any specific menu item.
You also learned how to completely remove menu links and their pages from the My Account page and show the 404-error page when someone tries to hit that endpoint.
I hope it helps you. If have any queries please do let me know in the comment section, I will respond to you as soon as possible.
See Also: Hide WooCommerce Payment Gateway Based on Shipping Class