Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class WC_Custom_My_Account_Tabs extends WC_Query {
/**
* Adds main filters and actions and inits the endpoints.
*/
public function __construct() {
add_action( 'init', array( $this, 'add_endpoints' ) );
if ( ! is_admin() ) {
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
add_filter( 'woocommerce_account_menu_items', array( $this, 'edit_navigation' ) );
add_action( 'woocommerce_account_custom_endpoint', array( $this, 'add_custom_tab_content' ) );
}
$this->init_query_vars();
}
/**
* Inits the query vars for WooCommerce
*/
public function init_query_vars() {
$this->query_vars = array(
'custom' => 'custom',
);
}
/**
* Edits the navigation in the page My Account, removing, editing and adding new tabs.
*
* @param array $items
* @return array
*/
public function edit_navigation( $items ) {
// Remove tabs
unset( $items['downloads'] );
// Rename tabs
$items['edit-address'] = 'My Custom Title';
// Add tabs
$items['custom'] = 'Custom Tab';
return $items;
}
/**
* Prints the custom tab content from a template in theme-name/woocommerce/myaccount/
*/
public function add_custom_tab_content() {
wc_get_template( 'myaccount/custom.php', array(), '', get_stylesheet() . 'woocommerce/' );
}
}
new WC_Custom_My_Account_Tabs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.