WooCommerce & Shop OperationsApr 21, 2021
How to Extend Navigation in the WooCommerce Customer Account.
You can easily extend the navigation for the customer account in WooCommerce, without any plugin.
For this, we use the filters woocommerce_account_menu_items and woocommerce_get_endpoint_url.
First, we add a new endpoint using the filter woocommerce_account_menu_items. Here, the displayed name (Custom Menu) of the link is set, and a custom endpoint (custom-endpoint) is defined.
/**
* add navigation items to woocommerce
*/
function addNavigationItemsToWooCommerce($items) {
$items['custom-endpoint'] = __('Custom Menu');
return $items;
}
add_filter('woocommerce_account_menu_items', 'addNavigationItemsToWooCommerce', 10, 1);
Next, we need to define a link for the endpoint. For this, we use the filter woocommerce_get_endpoint_url.
/**
* 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);
Now we have already set a link for our endpoint. Ideally, you should set the new endpoints in the WordPress backend and pull the selected post IDs from there. This way, you can adjust the links at any time without editing the PHP code.
Did you like the article? Then leave us a short comment. If you have questions, you can check out our Support Forum.