向特定用户角色显示woocommerce仪表板选项卡



我已经成功地在我的woocommerce仪表板上添加了一个额外的标签标题"Support"使用以下代码:

function tb_add_support_endpoint() {
add_rewrite_endpoint( 'support', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'tb_add_support_endpoint' );
function tb_support_query_vars( $vars ) {
$vars[] = 'support';
return $vars;
}
enter code here
add_filter( 'query_vars', 'tb_support_query_vars', 0 );
function tb_add_support_link_my_account( $items ) {
$items['support'] = 'Support';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'tb_add_support_link_my_account' );
function tb_support_content() {
echo '<h3>Support</h3><p>Have a question? Use the form below to get in touch.</p>';
echo do_shortcode( ' [wpforms id="XXX"] ' );
}
add_action( 'woocommerce_account_support_endpoint', 'tb_support_content' );

我想添加另一个选项卡,该选项卡仅对具有用户角色"partnersupport"的用户可见

我使用了上面的代码(将tb替换为tbvip)并尝试添加:

if ( current_user_can( 'partnersupport' ) ) {

:

if ( current_user_can( 'partnersupport' ) ) {
function tbvip_add_support_link_my_account( $items ) {
$items['support'] = 'VIP Support';
return $items; 
}
}

从我读到类似的线程,这应该工作,但它打破了一切为我。请告诉我如何达到我想要的结果。

在函数名后添加条件

function tbvip_add_support_link_my_account( $items ) {
if ( current_user_can( 'partnersupport' ) ) {
$items['support'] = 'VIP Support';
return $items;  
}
}

最新更新