woocommerce offtopic – Custom My Account tab isn’t working when Home Page is My Account page

Question

I have used the code snippet to add the custom my account page:

/**
 * Register new endpoint to use inside My Account page.
 *
 * Haseeb Asif https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
 */
function my_custom_endpoints() {
    add_rewrite_endpoint( 'my-custom-endpoint', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'my_custom_endpoints' );

/**
 * Add new query var.
 *
 * @param array $vars
 * @return array
 */
function my_custom_query_vars( $vars ) {
    $vars[] = 'my-custom-endpoint';

    return $vars;
}

add_filter( 'query_vars', 'my_custom_query_vars', 0 );

I’ve followed this documentation: https://github.com/woocommerce/woocommerce/wiki/Customising-account-page-tabs

and also added a new custom tab Title and Content which works fine.

However, when the home page is myaccount page.

enter image description here

the new account tab do not work anymore. It leads to the blog posts page.

Basically, the URL:

http://development.local/downloads/
http://development.local/edit-account/

works fine.

http://development.local/my-custom-endpoint/

doesnot.

When myaccount tab is not homepage:

http://development.local/my-account/my-custom-endpoint/
http://development.local/my-account/downloads/
http://development.local/my-account/edit-account/

all works fine.

I’ve already tried flushing the permalinks.

Thank you!

0
micky 1 month 2021-04-01T23:37:12-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse