Sometimes we need to add a new account menu item for Woocommerce. If you have the same problem the code below should get you 90% of the way there. Just need to build out your own template part.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
add_filter ( 'woocommerce_account_menu_items', 'jb_add_woo_item' ); function jb_add_woo_item( $menu_links ){ $new = array( 'attendance' => 'Seminar Attendance' ); // 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', 'jb_hook_endpoint', 10, 4 ); function jb_hook_endpoint( $url, $endpoint, $value, $permalink ){ if( $endpoint === 'attendance' ) { // ok, here is the place for your custom URL, it could be external $url = site_url().'/my-account/attendance/'; } return $url; } add_action( 'init', 'jb_attendance_new_endpoints' ); function jb_attendance_new_endpoints() { add_rewrite_endpoint( 'attendance', EP_ROOT | EP_PAGES ); } // MY ACCOUNT add_action( 'woocommerce_account_attendance_endpoint', 'jb_attendance_endpoint_content' ); function jb_attendance_endpoint_content() { get_template_part('templates/woocommerce/my-account/attendance'); } |