WooCommerce: Adding custom template to customer account pages WooCommerce: Adding custom template to customer account pages wordpress wordpress

WooCommerce: Adding custom template to customer account pages


This is a working solution for WooCommerce 2.6+ to extend and manipulate the tabbed "My Account" page endpoints (See this reference at the end of this answer), so here it is what you can do to achieve this:

add_action( 'init', 'custom_new_wc_endpoint' );function custom_new_wc_endpoint() {    add_rewrite_endpoint( 'edit-order', EP_ROOT | EP_PAGES );}add_filter( 'query_vars', 'custom_query_vars', 0 );function custom_query_vars( $vars ) {    $vars[] = 'edit-order';    return $vars;}add_action( 'after_switch_theme', 'custom_flush_rewrite_rules' );    function custom_flush_rewrite_rules() {    flush_rewrite_rules();}// The custom template locationadd_action( 'woocommerce_account_edit-order_endpoint', 'custom_endpoint_content' );function custom_endpoint_content() {    include 'woocommerce/myaccount/edit-order.php'; }

Then you will need, to Insert the new Edit order endpoint into the My Account menu:

add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );function custom_my_account_menu_items( $items ) {    // Remove the orders menu item.    $orders_item = $items['orders']; // first we keep it in a variable    unset( $items['orders'] ); // we unset it then    // Insert your custom endpoint.    $items['edit-order'] = __( 'Edit Order', 'woocommerce' );    // Insert back the logout item.    $items['orders'] = $orders_item; // we set it back    return $items;}

Important: You will need to flush the rewrite rules (2 ways):

  • Go to the Permalinks options page and re-save the permalinks (thanks to helgatheviking)
  • You can also disable/enable your theme.

References: