繁体   English   中英

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

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

我正在尝试将链接项目添加到 WooCommerce 我的帐户菜单中的另一个页面(我的 BuddyPress 页面)。 是否可以?

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

但是,我在 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;
}

其实,除了主要的问题,我改名字的时候,还被一个错误困扰。

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

[错误信息] 语法错误,意外的'' (T_STRING)

我用以下方法安全地解决了它:

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