Menu item renamed to the WooCommerce endpoint title

Hey,

I’ve used AI to help tidy up my rambling, but just let me know if you need any more details:


Bug report: menu item renamed to the WooCommerce endpoint title

Affects: HivePress 1.7.27 with WooCommerce 11.0 or newer. It cannot occur on WooCommerce 10.9.x or earlier, so please test against 11.0 (trunk or the release/11.0 branch).

Symptom: on a My Account endpoint such as Orders or Subscriptions, one nav menu item elsewhere on the page is renamed to the endpoint title, for example “Home” becomes “Orders”.

Cause
WooCommerce 11.0 added a queried-post guard to wc_page_endpoint_title() and registers it with two arguments:

function wc_page_endpoint_title( $title, $post_id = 0 ) {
   if ( ... && ( ! $post_id || get_queried_object_id() === $post_id ) ) {
add_filter( 'the_title', 'wc_page_endpoint_title', 10, 2 );

The function removes itself after its first successful swap, so HivePress re-adds it when building the account page, in includes/components/class-woocommerce.php line 468:

add_filter( 'the_title', 'wc_page_endpoint_title' );

WP_Hook::add_filter() keys callbacks by callback and priority and overwrites the existing entry (wp-includes/class-wp-hook.php, lines 87 to 94). So this line does not only re-add the callback after WooCommerce removed it: while WooCommerce’s own registration is still attached, it rewrites accepted_args from 2 back to 1.

With one accepted argument, $post_id falls back to its 0 default, ! $post_id is true, and the guard passes for every post. Walker_Nav_Menu::start_el() calls apply_filters( 'the_title', $menu_item->title, $menu_item->ID ) (wp-includes/class-walker-nav-menu.php line 234), so the next menu item rendered while the filter is live takes the endpoint title, and the filter then removes itself. That is why exactly one item changes.

Fix, line 468:

-			add_filter( 'the_title', 'wc_page_endpoint_title' );
+			add_filter( 'the_title', 'wc_page_endpoint_title', 10, 2 );

This is safe on every WooCommerce version: on 10.9.x and earlier wc_page_endpoint_title() takes one parameter, so the extra argument is simply ignored.


I hope this helps!

Cheers,
Chris :victory_hand:

Hi Chris,

Thanks for the detailed bug report, the issue is confirmed and will be fixed in the next HivePress core update.

1 Like