【发布时间】:2021-06-15 10:18:24
【问题描述】:
我想知道如何在 WooCommerce 中重新排列“我的帐户”页面上的菜单选项卡。
我使用下面的代码添加了一个名为“Affiliate Dashboard”的新菜单,但我想在“Log Out”菜单之前显示它,以便它出现在“Account Details”和“Log Out”菜单之间。
所以安排会是这样的。
1- 仪表板
2- 订单
3- 优惠券
4- 地址
5- 账户详情
6- 附属仪表板
7- 退出
请看截图。
//First hook that adds the menu item to my-account WooCommerce menu
function affiliate_home_link( $menu_links ){
// we will hook "womanide-forum" later
$new = array( 'affiliate-home' => 'Affiliate Dashboard' );
// or in case you need 2 links
// $new = 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, 5, true )
+ $new
+ array_slice( $menu_links, 5, NULL, true );
return $menu_links;
}
add_filter ( 'woocommerce_account_menu_items', 'affiliate_home_link' );
// Second Filter to Redirect the WooCommerce endpoint to custom URL
function affiliate_home_hook_endpoint( $url, $endpoint, $value, $permalink ){
if( $endpoint === 'example-forum' ) {
// This is where you add the custom URL, it could be external like, in this case, we need to go to my profile on the bbpress froum
// I will use this function (bp_core_get_username( bp_loggedin_user_id() );) to get my profile user id and add it to the URL as shown below
$url = site_url() .'/affiliate-home/' . bp_core_get_username( bp_loggedin_user_id() );
}
return $url;
}
add_filter( 'woocommerce_get_endpoint_url', 'forum_example_hook_endpoint', 10, 4 );
我们将不胜感激。
谢谢!
【问题讨论】:
标签: wordpress woocommerce