简体   繁体   English

在[woocommerce_my_account]的左侧添加自定义链接

[英]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. 我的帐户页面是由[woocommerce_my_account]加载的,在左侧带有链接,我需要在左侧菜单中添加自己的自定义页面,尽管由于来自短标签,所以无法执行此操作。

Is there a way to create a new WooCommerce end point and add in a pointer to my page? 有没有办法创建一个新的WooCommerce端点并添加指向我页面的指针?

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/ https://sarathlal.com/add-new-menu-item-my-account-navigation-woocommerce/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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