This is how you expand the navigation in the WooCommerce customer account.

Marc Wagner, July 22, 2022

You can easi­ly extend the cus­to­mer account navi­ga­ti­on in Woo­Com­mer­ce, wit­hout any plug­in.

For this, we resort to woocommerce_account_menu_items and woocommerce_get_endpoint_url fil­ters.

First, we add a new end­point via the woocommerce_account_menu_items fil­ter. Here we set the dis­play­ed name (cus­tom menu) of the link and defi­ne a cus­tom end­point.

/**
 * add navigation items to woocommerce
 */
function addNavigationItemsToWooCommerce($items) {
   $items['custom-endpoint'] = __('Custom Menu');
   return $items;
}
add_filter('woocommerce_account_menu_items', 'addNavigationItemsToWooCommerce', 10, 1);

Then, of cour­se, we need to defi­ne a link for the end­point. For this, we use the woocommerce_get_endpoint_url fil­ter.

/**
 * add custom endpoint url
 */
function addNavigationItemsCustomEndpoint($url, $endpoint, $value, $permalink){
    if('custom-endpoint' == $endpoint){ 
       // set the url for our custom endpoint
       $url = get_permalink(1); 
    } 
   return $url;
}
add_filter('woocommerce_get_endpoint_url', 'addNavigationItemsCustomEndpoint', 10, 4);

With this, we have also alre­a­dy depo­si­ted a link for our end­point. Ide­al­ly, you store the new end­points in the backend of Word­Press and drag the sel­ec­ted post IDs from the­re. This way, you can chan­ge the links at any time wit­hout editing the PHP code.

Did you like the artic­le? Then lea­ve us a short com­ment.

Avatar of Marc Wagner
Marc Wagner

Hi Marc here. I'm the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.

Similar Topics

Comments

Leave A Comment