简体   繁体   中英

How to reorder custom tab in woocommerce my account page?

I created a custom tab (My Favorites) for my Woocommerce my account page and placed the below code in my child theme's functions.php file. When I did that, the custom tab is ordered at the bottom of the rest of the tabs.

So I was wondering, is a way to reorder it further up the list of tabs?

Specifically I would like to reorder my custom tab (My Favorites) above the "Account Details" tab.

image link

function add_myfavorites_endpoint() {
    add_rewrite_endpoint( 'myfavorites', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'add_myfavorites_endpoint' );


function myfavorites_query_vars( $vars ) {
    $vars[] = 'myfavorites';
    return $vars;
}

add_filter( 'query_vars', 'myfavorites_query_vars', 0 );


function add_myfavorites_link_my_account( $items ) {
    $items['myfavorites'] = 'My Favorites';
    return $items;
}

add_filter( 'woocommerce_account_menu_items', 'add_myfavorites_link_my_account' );


function myfavorites_content() {
echo '<h3>My Favorites</h3><p>';
echo do_shortcode( ' [my_content_shortcode] ' );
}

add_action( 'woocommerce_account_myfavorites_endpoint', 'myfavorites_content' );
// Rename, re-order my account menu items
function fwuk_reorder_my_account_menu() {
    $neworder = array(
        'dashboard'          => __( 'Dashboard', 'woocommerce' ),
        'orders'             => __( 'Previous Orders', 'woocommerce' ),
        'wishlist-link'      => __( 'Wishlist', 'woocommerce' ),
        'edit-address'       => __( 'Addresses', 'woocommerce' ),
        'edit-account'       => __( 'Account Details', 'woocommerce' ),
        'customer-logout'    => __( 'Logout', 'woocommerce' ),
    );
    return $neworder;
}
add_filter ( 'woocommerce_account_menu_items', 'fwuk_reorder_my_account_menu' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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