Public Ticket #4576985

Sub account pages shows 404 error

Closed
Comments
2,762
KingsPlugins replied 2 months ago on July 29, 2026 at 10:36pm

Hi there,

In most cases when this happens, there is something else on the site interfering with how permalinks are saved. There are 2 things you can try here - please try them separately, so try A first, and if it doesn't solve it, revert A and try B:

A) In B2BKing -> Settings -> Other, try enabling the "Change My Account URL Structure" setting and see if that solves it.

B) Add this code snippet to the site (it can go in functions.php of the theme or any code snippets plugin):

add_filter('b2bking_flush_permalinks','__return_false');

Both of these change how permalinks are saved, so if something else is interfering, one of them may solve it permanently.

 

Other than that, it's hard to say more without knowing the setup in detail. If the above doesn't help, we'd be happy to investigate directly on the site - for that we would need a backend admin login or a staging clone site.

Kind regards,
Stefan

19 Tickets
TEWEB replied 2 months ago on July 30, 2026 at 11:19am

We already did these steps. also the snippet is already in our site. 

this is our developers findings. Maybe this could help 

 

Reply from developer: 

I'm reporting an intermittent 404 on the subaccounts My Account endpoint in B2BKing Pro 5.5.40. I've traced it in the plugin source and included exact file and line references below.

 

ENVIRONMENT -
B2BKing Pro 5.5.40 -
WooCommerce with HPOS enabled -
My Account page slug localized to "mein-konto"; the subaccounts endpoint slug   is the default "subaccounts"

 

 

SYMPTOM
The subaccounts page (e.g. /mein-konto/subaccounts/) works most of the time, but periodically returns a 404 for all users, then resolves again on its own after a while when a permalink flush is triggered. Nothing is written to the PHP error log during the failure, which is consistent with a missing rewrite rule rather than a fatal error.

 

 

ROOT CAUSE
The subaccounts rewrite endpoint is registered conditionally based on the current user, but rewrite rules are global — so the per-user condition ends up determining whether the URL resolves for everyone.

 

1) In public/class-b2bking-public.php, b2bking_custom_endpoints() (defined at line 10269, hooked to init at line 1006) only registers the subaccounts endpoints when the current user is NOT a subaccount:

 

       if (intval(get_option('b2bking_enable_subaccounts_setting', 1)) === 1){            $account_type = get_user_meta(get_current_user_id(),'b2bking_account_type', true);            if ($account_type !== 'subaccount'){                add_rewrite_endpoint( get_option('b2bking_subaccounts_endpoint_setting','subaccounts'), EP_ROOT | EP_PAGES | EP_PERMALINK );                add_rewrite_endpoint( get_option('b2bking_subaccount_endpoint_setting','subaccount'), EP_ROOT | EP_PAGES | EP_PERMALINK );            }        }

 

2) In the same file, force_permalinks_rewrite() (defined at line 18277, hooked to init at line 1056) re-registers the endpoints and then flushes the rewrite rules on each request by default:

 

       function force_permalinks_rewrite() {            ...            $this->b2bking_custom_endpoints();   // re-registers endpoints, subject to the same subaccount condition above            flush_rewrite_rules();               // rebuilds the stored rewrite rules        }

 

 

WHY IT IS INTERMITTENT

flush_rewrite_rules() rebuilds the stored rules from whatever endpoints are registered at that moment. When the flush runs during a subaccount's request, b2bking_custom_endpoints() takes the "$account_type === 'subaccount'" path (the condition at line 10288) and skips the add_rewrite_endpoint() calls, so the rebuilt rules no longer contain the subaccounts rule. The page then 404s for everyone until a request from a non-subaccount user (e.g. an admin or a logged-out visitor) triggers another rebuild with the endpoint present. As a result, the endpoint rule effectively toggles on and off depending on who most recently caused a rewrite rebuild. This occurs under a default configuration.

 

 

SUGGESTED FIX
Endpoint registration should not depend on the current user, since rewrite rules are global. The two add_rewrite_endpoint() calls (lines 10289-10290) could be moved outside the "if ($account_type !== 'subaccount')" check, so the endpoints are registered whenever subaccounts are enabled, regardless of who is browsing. The existing per-user gating on the My Account menu item and on the endpoint content callback would still keep the page hidden from subaccount users, but the rewrite rule would survive every rebuild and the URL would resolve consistently.

 

 

Thank you — I'm happy to provide logs or a staging reproduction if that would help.

2,762
KingsPlugins replied 2 months ago on August 4, 2026 at 12:58am

Hi there,

I looked into this and I've now implemented the change your developer suggested - the endpoints are now registered regardless of the current user. We agree this is a better way to handle it.

However,

1) B2BKing 5.5.40 also unconditionally adds all its endpoints via the woocommerce_get_query_vars filter, and WooCommerce then calls add_rewrite_endpoint() for each of those. So the rule should have sitll worked.

2) The mechanism your developer described would only explain issues with the subaccounts endpoint specifically. Could you confirm whether the other B2BKing My Account endpoints always work correctly, and it's only subaccounts that 404s?

 

Please try updating B2BKing Pro to the attached version and see if that resolves the issue.

If the attached version doesn't fully solve it, I think these are more likely causes:

Page/CDN/object cache inconsistency - a cached 404 can appear randomly and disappear after cache expiry or a permalink save.

Another component flushing rewrite rules in an incomplete context - many plugins flush rules on settings changes, language switches, scheduled tasks, etc.

Multilingual endpoint handling - if WPML/WCML, Polylang or similar is active, it can filter endpoint slugs and rewrite rules per language, which could explain issues as well,

 

Kind regards,
Stefan

19 Tickets
TEWEB replied 2 months ago on August 21, 2026 at 7:39pm

Hey!

We had installed the plugin you provided but after some days the issue appeared again. Can you please investigate further and resolve this issue.

Thank you!

2,762
KingsPlugins replied 1 month ago on August 22, 2026 at 1:24pm

Hi again,

Sorry to hear the issue came back.

 

I believe this points to something else on the site interfering with the rewrite rules - most likely another plugin or a caching layer flushing/overwriting them in a way that conflicts with B2BKing.

A few things to check on your end:

- Do you have any caching plugin active (e.g. WP Rocket, LiteSpeed, W3 Total Cache)?
- Is a multilingual plugin like WPML or Polylang active? These can interfere with endpoint slugs.
- Did you also try the code snippet we suggested previously? (`add_filter('b2bking_flush_permalinks','__return_false');`)

 

At this point I think the best next step would be for us to investigate directly on your site. If you could provide a backend admin login to the site or a staging clone, we can dig into this deeper.

Kind regards,
Stefan

Sign In