How to add new item in the woocommerce my account page

Wordpress tutorials

WooCommerce is a powerful plugin for online bussiness. Sometimes we need to add a new item to WooCommerce my account page dashboard. we can do it also with the plugin but it is not free. Customize My Account for WooCommerce 

The WooCommerce My Account page is one of the most important pages within WooCommerce. It holds important information for your customers such as orders, their addresses, payment methods, account details, and other endpoints. Since the My Account page is such an important information hub, shop owners might want to add new custom my account endpoints to showcase other information and customize the look and feel of the My Account page.

But we have a way to do this without using any plugin. just follow the below step.

Step 1:

Use the below code in a function.php to add an item to my account page menu.

add_filter ( 'woocommerce_account_menu_items', 'mboiblack_video_tuto' );
function mboiblack_video_tuto( $menu_links ){
 
    // we will hook "anyuniquetext123" later
    $new = array( 'video-tutorials' => 'Video Tutorials' );
 
    // or in case you need 2 links
    // $new = array( 'link1' => 'Link 1', 'link2' => 'Link 2' );
 
    // array_slice() is good when you want to add an element between the other ones
    $menu_links = array_slice( $menu_links, 0, 1, true ) 
    + $new 
    + array_slice( $menu_links, 1, NULL, true );
 
 
    return $menu_links;
 
 
}

Step 3:

Use the below code in a function.php to add an item menu page link.

 
add_filter( 'woocommerce_get_endpoint_url', 'mboiblack_hook_endpoint', 10, 4 );
function mboiblack_hook_endpoint( $url, $endpoint, $value, $permalink ){
 
    if( $endpoint === 'video-tutorials' ) {
 
        // ok, here is the place for your custom URL, it could be external
        $url = site_url()."/video-tutorials";
 
    }
    return $url;
 
}

 

Get Full Code:

add_filter ( 'woocommerce_account_menu_items', 'mboiblack_video_tuto' );
function mboiblack_video_tuto( $menu_links ){
 
    // we will hook "anyuniquetext123" later
    $new = array( 'video-tutorials' => 'Video Tutorials' );
 
    // or in case you need 2 links
    // $new = array( 'link1' => 'Link 1', 'link2' => 'Link 2' );
 
    // array_slice() is good when you want to add an element between the other ones
    $menu_links = array_slice( $menu_links, 0, 1, true ) 
    + $new 
    + array_slice( $menu_links, 1, NULL, true );
 
 
    return $menu_links;
 
 
}
 
add_filter( 'woocommerce_get_endpoint_url', 'mboiblack_hook_endpoint', 10, 4 );
function mboiblack_hook_endpoint( $url, $endpoint, $value, $permalink ){
 
    if( $endpoint === 'video-tutorials' ) {
 
        // ok, here is the place for your custom URL, it could be external
        $url = site_url()."/video-tutorials";
 
    }
    return $url;
 
}

 

Result

How to disable WordPress admin bar from front end without plugin

How to active windows 10| Easy Way | Remove windows watermark | windows 10 pro/ Pro N

Releted Post