Anonymous Anonymous - 25 days ago
420 0

I created this snippet order to add my extra item (videos). It basically rewrites the menu items. There might be a more elegant solution to 'insert' the extra menu item but this works and has been live on a busy site for a few months.

PHP

Add Woocommerce My Account menu item

/* 
Add account menu item
*/
function MD_custom_my_account_menu_items( $items ) {
    $items = array(
        'dashboard'         => __( 'Dashboard', 'woocommerce' ),
        'orders'            => __( 'My Orders', 'woocommerce' ),
        'downloads'       => __( 'My Downloads', 'woocommerce' ),
	'videos'       => __( 'My Videos', 'woocommerce' ),
        'edit-address'    => __( 'Edit Address', 'woocommerce' ),
        'edit-account'      => __( 'Edit Account', 'woocommerce' ),
        'customer-logout'   => __( 'Logout', 'woocommerce' ),
    );
    return $items;
}

add_filter( 'woocommerce_account_menu_items', 'MD_custom_my_account_menu_items' );

/* 
Add endpoint 
*/
function MD_add_my_account_endpoint() {
    add_rewrite_endpoint( 'videos', EP_PAGES );
}
 
add_action( 'init', 'MD_add_my_account_endpoint' );

/*
Page content 
*/
function MD_videos_endpoint_content() {
  echo '<p><b>On-demand videos you have purchased in the <a href="/shop">shop</a> will be listed here:</b></p>';
  echo do_shortcode( '<div class="my-video-list">[woocommerce-payperpost template="purchased"]</div>' );
}
 
add_action( 'woocommerce_account_videos_endpoint', 'MD_videos_endpoint_content' );