I customise my woocommerce account pages by adding new endpoints successfully.
The title oh this new endpoints is "My account" default title. I would like to customize the title as well.
I tried with the hook "woocommerce_endpoint_{endpoints}_title", which works perfectly on defaults endpoints, but it doesn’t seem to work on custom endpoint :
My custom endpoint (not working):
add_filter( 'woocommerce_endpoint_favoris_title', 'change_my_account_favoris_title', 10, 2 );
function change_my_account_favoris_title( $title, $endpoint ) {
$title = __( "Tests", "woocommerce" );
return $title;
}
Default endpooint example working:
add_filter( 'woocommerce_endpoint_edit-account_title', 'change_my_account_edit_title', 10, 2 );
function change_my_account_edit_title( $title, $endpoint ) {
$title = __( "Tests", "woocommerce" );
return $title;
}
Can’t find anything on this for now,
Thanks for your time
EDIT:
My complete hooks of my woocommerce account section:
1/ Creation of endpoints :
add_filter ('woocommerce_account_menu_items', 'custom_log_history_link', 40);
function custom_log_history_link($menu_links){
$menu_links = array_slice( $menu_links, 0, 5, true )
+ array( 'favoris' => 'Mes favoris' )
+ array_slice( $menu_links, 5, NULL, true )
+ array( 'delete-account' => 'Supprimer mon compte' )
+ array_slice( $menu_links, 5, NULL, true );
return $menu_links;
}
add_action( 'init', 'custom_add_endpoint' );
function custom_add_endpoint() {
add_rewrite_endpoint( 'favoris', EP_PAGES );
add_rewrite_endpoint( 'delete-account', EP_PAGES);
}
2/ Content of new endpoints:
add_action( 'woocommerce_account_favoris_endpoint', 'custom_my_account_endpoint_content_favoris' );
function custom_my_account_endpoint_content_favoris() {
$user = wp_get_current_user();
$user_id=$user->ID;
$favoris=get_field('liste_des_favoris','user_'.$user_id);
$favoris_id=array();
echo "<h3>Vos produits favoris :</h3>";
if ($favoris!=''){
foreach ($favoris as $favori) {
$favoris_id[] = $favori['produit_favori'];
}
echo '<ul class="list-produits">';
foreach($favoris as $favori){
$product=wc_get_product($favori['produit_favori']);
$product = $product->get_data();
$sidebar = true;
ItemProduit($product,$sidebar,$favoris_id,$user_id);
}
echo '</ul>';
} else {
echo "<p>Vous n'avez pas de favoris pour le moment1.</p>";
}
}
add_action( 'woocommerce_account_delete-account_endpoint', 'custom_my_account_endpoint_content' );
function custom_my_account_endpoint_content() {
echo "<p>Etes-vous sûr de vouloir supprimer défintivement votre compte ?<br/>Attention ! Toute suppression de compte est définitive, vous perdrez tout l'historique de vos achats.<br/>En supprimant votre compte, toutes vos données personnelles seront définitivement effacées de notre base de données.</p>";
echo '<p class="status"></p>';
wp_nonce_field( 'ajax-delete-nonce', 'delete-security' );
echo '<div class="btns-delete">';
echo '<div class="btn btn-red" id="submit-delete">Supprimer</div>';
echo '</div>';
}
3/ Custom menu order :
add_filter ( 'woocommerce_account_menu_items', 'custom_sort_menu' );
function custom_sort_menu( $menu_links ){
$menu_links = array(
'dashboard' => 'Tableau de bord',
'orders' => 'Mes commandes',
'favoris' => 'Mes favoris',
'edit-address' => 'Mes adresses',
'edit-account' => 'Détails du compte',
'customer-logout' => 'Déconnexion',
'delete-account' => 'Supprimer mon compte',
);
return $menu_links;
}
2
Answers
One way of changing the title of the custom WooCommerce endpoints is to use
the_title
filter with thein_the_loop
conditionalHere is an example that you’ll need to modify per your own requirements.
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 inwoocommerce_get_query_vars
filter hook as follows:Then to change that custom endpoints titles you can use effectively:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
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