Skip to content

Instantly share code, notes, and snippets.

@ferndot
Created May 3, 2018 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferndot/fafa03d74e9662b38736d0a3526582e9 to your computer and use it in GitHub Desktop.
Save ferndot/fafa03d74e9662b38736d0a3526582e9 to your computer and use it in GitHub Desktop.
WooCommerce My Account Custom Tabs
<?php
/*
Add My Account endpoints
*/
function custom_endpoints() {
add_rewrite_endpoint('page1', EP_ROOT | EP_PAGES);
add_rewrite_endpoint('page2', EP_ROOT | EP_PAGES);
}
function custom_query_vars($vars) {
$vars[] = 'page1';
$vars[] = 'page2';
return $vars;
}
add_filter('query_vars', 'custom_query_vars', 0);
function custom_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action('wp_loaded', 'custom_flush_rewrite_rules');
function custom_my_account_menu_items($items) {
// Insert before 'orders'
$page1MenuItem = ['page1' => 'Page 1'];
array_insert($items, 'orders', $page1MenuItem);
// Insert before 'customer-logout'
$page2MenuItem = ['page2' => 'Page 2'];
array_insert($items, 'customer-logout', $page2MenuItem);
return $items;
}
add_filter('woocommerce_account_menu_items', 'custom_my_account_menu_items');
function custom_endpoint_content_page1() {
include 'path/to/page1template.php';
}
add_action('woocommerce_account_page1_endpoint', 'custom_endpoint_content_page1');
function custom_endpoint_content_page2() {
include 'path/to/page2template.php';
}
add_action('woocommerce_account_page2_endpoint', 'custom_endpoint_content_page2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment