我正在尝试将链接项目添加到WooCommerce My帐户菜单中的另一个页面(我的BuddyPress页面(。有可能吗?
我看到了此线程:如何将外部自定义URL添加到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;
}
实际上,除了主要问题外,当我更改名称时,我会遇到错误。
[更改]'**候选仪表板**' - &gt;'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;
}