douqiao1887 2017-12-19 14:42
浏览 206
已采纳

在“Woocommerce我的帐户”部分重新排序菜单项

I want to move the "Langgan" menu label (for subscriptions key) on top of "Dashboard" and bold the "Langgan".

Currently I'm using the code below for "Langgan" part inside my theme function.php file:

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;
}

enter image description here

  • 写回答

1条回答 默认 最新

  • doutan8601 2017-12-19 15:36
    关注

    To set a custom label for 'subscriptions' key and reorder menu items to get it at the beginning, try this instead (this will replace your function):

    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;
    }
    

    This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and works


    To make "Langgan" Bold you should need to add in your styles.css file located in your active theme, the following CSS rule:

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

    OR

    nav.woocommerce-MyAccount-navigation > ul > li:first-child {
        font-weight: bold !important;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀