1

I'm trying to create a custom page in My Account section of Woocommerce, but when I open this page I get 404 (Page not found). I tried to re-save (refresh) the permalinks in Settings -> Permalinks, but nothing changes (again 404 - Page not found). I'm using this permalink type "https://mywebsite.com/sample-post/". When I change the permalink type to "https://mywebsite.com/?p=123" it is working and the page shows. Can somebody tell me where is the problem and why it's working with "Plain" permalinks, but it's not working with "Post name" permalinks ? Here is my code snippet:

// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error
  
function bbloomer_add_premium_support_endpoint() {
    add_rewrite_endpoint( 'premium-support', EP_ROOT | EP_PAGES );
}
  
add_action( 'init', 'bbloomer_add_premium_support_endpoint' );
  
  
// ------------------
// 2. Add new query var
  
function bbloomer_premium_support_query_vars( $vars ) {
    $vars[] = 'premium-support';
    return $vars;
}
  
add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 );
  
  
// ------------------
// 3. Insert the new endpoint into the My Account menu
  
function bbloomer_add_premium_support_link_my_account( $items ) {
    $items['premium-support'] = 'Premium Support';
    return $items;
}
  
add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' );
  
  
// ------------------
// 4. Add content to the new endpoint
  
function bbloomer_premium_support_content() {
echo '<h3>Premium WooCommerce Support</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>';
echo do_shortcode( ' /* your shortcode here */ ' );
}
  
add_action( 'woocommerce_account_premium-support_endpoint', 'bbloomer_premium_support_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
  • The code works just fine with "Post name" permalinks… So there is something else that is making trouble in your case, like another plugin, your theme or some other custom code. – LoicTheAztec Jul 23 '20 at 21:09
  • I tried and stopped all plugins and snippets. Also tried to change the theme to the default one, but there is no change - it's returning Page not found (404). The interesting thing is that if I change the permalinks type to be "Plain" it's working... – C0nstruct0r Jul 24 '20 at 13:33
  • For me it works and I have a similar working answers on StackOverFlow: https://stackoverflow.com/questions/38051331/woocommerce-adding-custom-template-to-customer-account-pages/38057611#38057611 – LoicTheAztec Jul 24 '20 at 13:41

1 Answers1

4

Could you please go to Settings -> Permalinks and try to re-save it and check again.

  • This does not provide an answer to the question. Once you have sufficient [reputation](/help/whats-reputation) you will be able to [comment on any post](/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – STA Feb 28 '21 at 14:35
  • It works for me, but please provide detailed reasoning – Farhat Aziz Aug 28 '21 at 17:15