I wanted to remove the home/dashboard menu item in the Woocommerce my account dashboard and found a great snippet to redirect the visitors from the dashboard to another page upon arrival. This way both the menu item is gone and the page is inaccessible.
I found the snippet on Misha Rudrastyh‘s website, in the following article:
https://rudrastyh.com/woocommerce/remove-dashboard-from-my-account-menu.html
But after the change, my custom pages stopped working.
Apparently, my custom pages were not registered in Woocommerce’s query vars so the WC()->query->get_current_endpoint()
function would return empty thinking the visitor requested the dashboard/home page.
The right way of setting up menu items and custom pages in Woocommerce my account
Woocommerce allows us to alter the menu items and pages with a couple of neat hooks like:
woocommerce_account_menu_items
woocommerce_account_***_endpoint
woocommerce_get_query_vars
.
The GIST below shows how we can use these hooks together with Misha’s snippet.
Piotr Madej says
Bingo, couldn’t have figured it myself for almost 2 hours, then found this post. Thank you!