需要创建一个操作挂钩“woocommerce\\u account\\u[myendpoint]\\u 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/
因此,将几个不同的来源放在一起,要向Woocommerce我的帐户仪表板添加一个新的菜单项,需要如下内容:
<?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();
}