简体   繁体   English

如何将链接项目添加到 WooCommerce 我的帐户菜单中的另一个页面

[英]How to add a linked item to another page in WooCommerce My Account menu

I am trying to add a linked item to another page (My page of BuddyPress) in the menu of WooCommerce My account.我正在尝试将链接项目添加到 WooCommerce 我的帐户菜单中的另一个页面(我的 BuddyPress 页面)。 Is it possible?是否可以?

I saw this thread: How to add external custom url to woocommerce endpoint我看到了这个帖子: How to add external custom url to woocommerce endpoint

However, my page on BuddyPress could not be used because it could not be written in ULR and could not be written in (May be just my lack of knowledge) :但是,我在 BuddyPress 上的页面无法使用,因为它无法用 ULR 编写,也无法写入(可能只是我缺乏知识)

add_filter ( 'woocommerce_account_menu_items', 'add_menu_item_to_tabbed_my_account' );
function add_menu_item_to_tabbed_my_account( $menu_links ){

    // we will hook "anyuniquetext123" later
    $new_item = array( 'anyuniquetext123' => __('Candidate Dashboard') );

    // or in case you need 2 links
    // $new_item = array( 'link1' => 'Link 1', 'link2' => 'Link 2' );

    // array_slice() is good when you want to add an element between the other ones
    $menu_links = array_slice( $menu_links, 0, 1, true ) 
    + $new_item 
    + array_slice( $menu_links, 1, NULL, true );

    return $menu_links;
}

add_filter( 'woocommerce_get_endpoint_url', 'custom_endpoint_url', 10, 4 );
function custom_endpoint_url( $url, $endpoint, $value, $permalink ){

    if( $endpoint === 'anyuniquetext123' ) {

        // BuddyPress My page link → <?php echo bp_loggedin_user_domain(); ?>
        // I want to make a link of this
        // ok, here is the place for your custom URL, it could be external
        $url = **'http://alatta.org.ye/candidate-dashboard/';**

    }
    return $url;
}

Actually, in addition to the main problem, when I change the name, I am troubled with an error.其实,除了主要的问题,我改名字的时候,还被一个错误困扰。

[Change] '** Candidate Dashboard **' -> 'aaa' [更改] '** 候选人仪表板 **' -> 'aaa'

[Error message] syntax error, unexpected '' (T_STRING) [错误信息] 语法错误,意外的'' (T_STRING)

I solved it safely with the following:我用以下方法安全地解决了它:

add_filter ( 'woocommerce_account_menu_items', 'add_menu_item_to_tabbed_my_account' );
function add_menu_item_to_tabbed_my_account( $menu_links ){
    $new_item = array( 'anyuniquetext123' => __('Candidate Dashboard') );

    $menu_links = array_slice( $menu_links, 0, 1, true ) 
    + $new_item 
    + array_slice( $menu_links, 1, NULL, true );
 
    return $menu_links;
}
 
add_filter( 'woocommerce_get_endpoint_url', 'custom_endpoint_url', 10, 4 );
function custom_endpoint_url( $url, $endpoint, $value, $permalink ){
    if( $endpoint === 'anyuniquetext123' ) {
 
        // I only had to describe it normally
        $url =  bp_loggedin_user_domain();
    }
    
    return $url;
}

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

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