簡體   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