1

I already added new endpoint to my account page, "my-account/My-New-Endpoint".

I would like to add sub page endpoint to that like "my-account/My-New-Endpoint/New-Subendpoint"

I can't find any info anywhere on how to do that.

I'm specifying endpoints like so:

$endpoint = 'my-new-endpoint';
$endpointsub = 'my-new-endpoint/new-subendpoint';

That does not work it loads content from first endpoint.

If I change it to $endpointsub = 'new-subendpoint'; it works but url becomes "my-account/New-Subendpoint"

Is there a specific way to create page/subpage endpoint to be like:"my-account/My-New-Endpoint/New-Subendpoint"?

Thank you.

EDIT:

This is add endpoint function:

function add_endpoints() {
        add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );
        add_rewrite_endpoint( self::$endpointsub, EP_ROOT | EP_PAGES );
    }

migrated from stackoverflow.com Dec 15 '17 at 4:35

This question came from our site for professional and enthusiast programmers.

  • have your tried your last code but in defining the subendpoint first ? – mmm Dec 14 '17 at 22:36
  • WooCommerce questions are just off topic on Here… So why this question has been migrated here? It should remains on StackOvereFlow. – LoicTheAztec Dec 15 '17 at 4:47
  • @mmm I just tried only changing first part and didn't change, once I did same on all parts of code it worked, example: add_query_vars( $vars ) { $vars[] = self::$endpointsub; $vars[] = self::$endpoint; return $vars; } Thank you. I wonder why that is? defining subpage endpoints first. In any case that worked. – Damir Gasparlin Dec 15 '17 at 5:51
1

Thanks to @mmm and his comment defining $endpointsub before $endpoint it worked. Not sure why that is but that solved it.

So change the order of endpoints:

$endpointsub = 'my-new-endpoint/new-subendpoint';
$endpoint = 'my-new-endpoint';

add_rewrite_endpoint( self::$endpointsub, EP_ROOT | EP_PAGES );
add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );

add_query_vars( $vars ) {
        $vars[] = self::$endpointsub;
        $vars[] = self::$endpoint;

        return $vars;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.