You can easily extend the customer account navigation in WooCommerce, without any plugin.
For this, we resort to woocommerce_account_menu_items and woocommerce_get_endpoint_url filters.
First, we add a new endpoint via the woocommerce_account_menu_items filter. Here we set the displayed name (custom menu) of the link and define a custom endpoint.
/**
* 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 course, we need to define a link for the endpoint. For this, we use the woocommerce_get_endpoint_url filter.
/**
* 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 already deposited a link for our endpoint. Ideally, you store the new endpoints in the backend of WordPress and drag the selected post IDs from there. This way, you can change the links at any time without editing the PHP code.
Did you like the article? Then leave us a short comment.
Comments