I am working on a project where my account page is a homepage. So what I did I have created a page that holding the shortcode [woocommerce_my_account]
and made this page homepage from Dashboard->Settings->Reading. Everything works. I have this working endpoints too:
- mydomain.com/orders
- mydomain.com/edit-address
But I am facing trouble when I am making a custom myaccount endpoint. I am doing it in this traditional way:
add_action('woocommerce_account_custom-endpoint_endpoint', function(){
echo 'hello';
} );
add_action('init', function() {
add_rewrite_endpoint('custom-endpoint', EP_ROOT | EP_PAGES);
});
But mydomain.com/custom-endpoint is not pointing to my account page, it is pointing to the index.php or page.php (WordPress template hierarchy).
I am curious to know why it is happening?
My Answer:
> Appearance > Customize > Homepage Settings
Now, I want to add a custom endpoint menu item in the My Account menu. To do this, you can use the following code snippet in your theme's functions.php file:
php
// Add custom endpoint to My Account menu
function custom_my_account_menu_items( $items ) {
$items['custom-endpoint'] = __( 'Custom Endpoint', 'text-domain' );
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
// Add custom endpoint content
function custom_my_account_endpoint_content() {
echo 'This is the content for the custom endpoint.
';
}
add_action( 'woocommerce_account_custom-endpoint_endpoint', 'custom_my_account_endpoint_content' );
Replace `'Custom Endpoint'` with the name of your custom endpoint and `'text-domain'` with your theme's text domain.
Now, when you visit the My Account page, you should see a new menu item called "Custom Endpoint" with the content you specified.
Rate this post
4 of 5 based on 6615 votesComments