简体   繁体   中英

Adding a custom link to left of [woocommerce_my_account]

The my account page gets loaded by [woocommerce_my_account] On the left side comes with links, I need to add in my own custom page into the left menu although there is no way to do it since this comes from a short tag.

Is there a way to create a new WooCommerce end point and add in a pointer to my page?

Maybe even a hook? I've tried multiple but had no results.

First create a new menu item to My Account menu.

/*
 * Step 1. Add new menu item to My Account menu - on the 3rd position.
 */
add_filter ( 'woocommerce_account_menu_items', 'xrgty37_new_menu_link', 40 );
function xrgty37_new_menu_link( $menu_links ){

    $menu_links = array_slice( $menu_links, 0, 2, true ) 
    + array( 'new-menu' => 'New Menu' )
    + array_slice( $menu_links, 2, NULL, true );

    return $menu_links;

}

Then register permalink end point for new menu item.

/*
 * Step 2. Register Permalink Endpoint
 */
add_action( 'init', 'xrgty37_add_endpoint' );
function xrgty37_add_endpoint() {

    // Check WP_Rewrite
    add_rewrite_endpoint( 'new-menu', EP_PAGES );

}

After registering the permalink end point, go to permalink settings & save settings.

Last, display some content on the newly created page.

/*
 * Step 3. Content for the new page in My Account, woocommerce_account_{ENDPOINT NAME}_endpoint
 */
add_action( 'woocommerce_account_new-menu_endpoint', 'xrgty37_my_account_endpoint_content' );
function xrgty37_my_account_endpoint_content() {

    // Content for new page
    echo 'This is content for newly created menu item.';

}

Here is my blog post.

https://sarathlal.com/add-new-menu-item-my-account-navigation-woocommerce/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM