You can’t add alumni-portal/alumni-index
as a separate endpoint, because this clashes with the alumni-portal
endpoint. This is because rewrite endpoints will capture anything after /
as their value. So alumni-portal/alumni-index
is the same as alumni-portal
, but the alumni-portal
query var is set to alumni-index
.
So rather than registering both endpoints, register alumni-portal
a single endpoint, and then check for which value for alumni-portal
is passed. If the value is index
, then display the appropriate template.
So register your endpoint with the woocommerce_get_query_vars
filter:
add_filter(
'woocommerce_get_query_vars',
function( $query_vars ) {
$query_vars['alumni'] = 'alumni';
return $query_vars;
}
);
Then use the woocommerce_account_alumni_endpoint
action to display the page. These account endpoint hooks will pass the “value” of the endpoint as an argument to the callback function. So if I visit my-account/alumni/index
the value passed will be index
, and you can use this to display the appropriate template:
add_action(
'woocommerce_account_alumni_endpoint',
function( $value ) {
if ( $value === 'index' ) {
wc_get_template( 'myaccount/alumni-index.php' );
} else {
wc_get_template( 'myaccount/alumni-portal.php' );
}
}
);
If you’re filtering the account page title you don’t get the value passed, but since you do get the endpoint you can get this with get_query_var()
:
add_filter(
'woocommerce_endpoint_alumni_title',
function( $title, $endpoint ){
$value = get_query_var( $endpoint );
if ( $value === 'index' ) {
$title="Alumni Index";
} else {
$title="Alumni Portal";
}
return $title;
},
10,
2
);