重新排列Woocommerce我的帐户部分中的菜单项 [英] Reorder menu items in Woocommerce My Account section

查看:79
本文介绍了重新排列Woocommerce我的帐户部分中的菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  add_filter('woocommerce_account_menu_items','rename_my_account_menu_items',0,15); 
函数named_my_account_menu_items($ items){

//在此处为订阅设置新标签名
$ items ['subscriptions'] = __('Custom label','woocommerce ');

返回$项;
}

解决方案

'subscriptions'键设置自定义标签并重新排序菜单项以获取首先,请尝试使用(这将替换您的函数)

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

//在此数组中为'subscriptions'键设置自定义标签名称
$ subscription_item = array('subscriptions'=> __('Langgan','woocommerce')) ;

//从原始$ items数组中删除 subscriptions键/标签对
unset($ items [’subscriptions]);

//合并数组
$ items = array_merge($ subscription_item,$ items);

返回$项;
}

此代码包含在活动子主题的function.php文件中(或主题)或任何插件文件中。



经过测试并有效






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



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

OR



<上课前= lang-css prettyprint-override> nav.woocommerce-MyAccount-navigation> ul> li:first-child {
font-weight:bold!important;
}


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

解决方案

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

这篇关于重新排列Woocommerce我的帐户部分中的菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆