簡體   English   中英

在[woocommerce_my_account]的左側添加自定義鏈接

[英]Adding a custom link to left of [woocommerce_my_account]

我的帳戶頁面是由[woocommerce_my_account]加載的,在左側帶有鏈接,我需要在左側菜單中添加自己的自定義頁面,盡管由於來自短標簽,所以無法執行此操作。

有沒有辦法創建一個新的WooCommerce端點並添加指向我頁面的指針?

甚至還有一個鈎子? 我嘗試了多次,但沒有結果。

首先在“我的帳戶”菜單中創建一個新菜單項。

/*
 * 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;

}

然后為新菜單項注冊永久鏈接端點。

/*
 * 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 );

}

注冊永久鏈接端點后,轉到永久鏈接設置並保存設置。

最后,在新創建的頁面上顯示一些內容。

/*
 * 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.';

}

這是我的博客文章。

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