One needs to create an action hook ‘woocommerce_account_[myendpoint]_endpoint’:
add_action('woocommerce_account_' . $endpoint . '_endpoint', 'my_endpoint_content');
function my_endpoint_content() {
//content goes here
echo 'My content goes here';
}
http://hookr.io/actions/woocommerce_account_key_endpoint/
So, putting a few different sources together, to add a new menu item to the Woocommerce My Account dashboard one needs something like:
<?php
add_filter('woocommerce_account_menu_items', 'add_my_menu_items');
function add_my_menu_items($items) {
$my_items = array('2nd-item' => __('2nd Item', '[my_plugin]'),);
$my_items = array_slice($items, 0, 1, true) +
$my_items +
array_slice($items, 1, count($items), true);
return $my_items;
}
//so, for...
$endpoint="2nd-item";
add_action('init', 'my_custom_endpoint');
function my_custom_endpoint() {
add_rewrite_endpoint('2nd-item', EP_ROOT | EP_PAGES);
}
add_action('woocommerce_account_' . $endpoint . '_endpoint', 'my_endpoint_content');
function my_endpoint_content() {
//content goes here
echo 'My content goes here';
}
add_filter('query_vars', 'my_custom_query_vars', 0);
function my_custom_query_vars($vars) {
$vars[] = '2nd-item';
return $vars;
}
add_action('wp_loaded', 'my_custom_flush_rewrite_rules');
function my_custom_flush_rewrite_rules() {
flush_rewrite_rules();
}