![](/img/trans.png)
[英]Add a custom item above logout item in Woocommerce my account menu
[英]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.