繁体   English   中英

重新排列Woocommerce我的帐户部分中的菜单项

[英]Reorder menu items in Woocommerce My Account section

我想将“ Langgan”菜单标签(用于订阅键)移到“仪表板”顶部,并加粗“ Langgan”。

当前,我在主题function.php文件中使用以下“ Langgan”部分的代码:

add_filter( 'woocommerce_account_menu_items', 'rename_my_account_menu_items', 0, 15 );
function rename_my_account_menu_items( $items ) {

    // HERE set your new label name for subscriptions
    $items['subscriptions'] = __( 'Custom label', 'woocommerce' );

    return $items;
}

在此处输入图片说明

要为'subscriptions'键设置自定义标签并重新排序菜单项以使其一开始就可以使用,请尝试以下操作(这将替换您的功能)

add_filter( 'woocommerce_account_menu_items', 'rename_my_account_menu_items', 100, 1 );
function rename_my_account_menu_items( $items ) {
    $ordered_items = array();

    // HERE set your custom label name for 'subscriptions' key in this array
    $subscription_item = array( 'subscriptions' => __( 'Langgan', 'woocommerce' ) );

    // Remove 'subscriptions' key / label pair from original $items array
    unset( $items['subscriptions'] );

    // merging arrays
    $items = array_merge( $subscription_item, $items );

    return $items;
}

这段代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中。

经过测试和工作


要使“ Langgan”变为粗体,您需要添加位于活动主题中的styles.css文件,并遵循以下CSS规则:

li.woocommerce-MyAccount-navigation-link--subscriptions {
    font-weight: bold !important;
}

要么

nav.woocommerce-MyAccount-navigation > ul > li:first-child {
    font-weight: bold !important;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM