Set My Account custom items endpoints titles in WooCommerce
To allow the composite filter hook woocommerce_endpoint_{$endpoint}_title
to work with custom My Account endpoints, there is something missing from your code. You need to declare those endpoints as query vars in woocommerce_get_query_vars
filter hook as follows:
add_filter( 'woocommerce_get_query_vars', 'myaccount_custom_endpoints_query_vars' );function myaccount_custom_endpoints_query_vars( $query_vars ) { $query_vars['favoris'] = 'favoris'; $query_vars['delete-account'] = 'delete-account'; return $query_vars;}
Then to change that custom endpoints titles you can use effectively:
add_filter( 'woocommerce_endpoint_favoris_title', 'change_my_account_favoris_title' );function change_my_account_favoris_title( $title ) { return __( "Favoris", "woocommerce" );}add_filter( 'woocommerce_endpoint_delete-account_title', 'change_my_account_delete_account_title' );function change_my_account_delete_account_title( $title ) { return __( "Supprimer mon compte", "woocommerce" );}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Remember to refresh rewrite rules by saving changes on Wordpress settings "Permalinks" section.
Other notes:
In your actual code, you are using 2 times the hook woocommerce_account_menu_items
in 2 functions… You need just one of them
One way of changing the title of the custom WooCommerce endpoints is to use the_title
filter with the in_the_loop
conditional
Here is an example that you'll need to modify per your own requirements.
function wpb_woo_endpoint_title( $title, $id ) { if ( is_wc_endpoint_url( 'downloads' ) && in_the_loop() ) { // add your endpoint urls $title = "Download MP3s"; // change your entry-title } elseif ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) { $title = "My Orders"; } elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) { $title = "Change My Details"; } return $title;}add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );