简体   繁体   中英

Changing the titles on My Account pages in Woocommerce

I've seen loads of example of how to re-order / change the navigation and page with the WooCommerce my account dashboard. But i can't for the life of me work out how to change the main titles for each section (My Account, Orders, Downloads, Addresses etc).

I've searched through the templates but no joy. I've tried using conditional php comments to echo the titles for the correct page. But it doesn't work because my account section uses endpoints. I've tried adding a filter, but no joy. Anyone got any idea how i change these titles?

Thanks

It can be done using the composite filter hook woocommerce_endpoint_{$endpoint}_title .

For example if you need to change the My Account "** Account details**" title you will use (where the endpoint is edit-account ) :

add_filter( 'woocommerce_endpoint_edit-account_title', 'change_my_account_edit_account_title', 10, 2 );
function change_my_account_edit_account_title( $title, $endpoint ) {
    $title = __( "Edit your account details", "woocommerce" );

    return $title;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

在此处输入图片说明

发现我可以使用 woo_endpoint_title 过滤器。

This worked for me to rename the titles of all my account pages:

function wpb_woo_endpoint_title( $title, $id ) {
           
            if ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
                $title = "Deine Buchungen";
            }
            elseif ( is_wc_endpoint_url( 'edit-address' ) && in_the_loop() ) {
                $title = "Deine Rechnungs- & Behandlungsadresse"; 
            }
            elseif ( is_wc_endpoint_url( 'payment-methods' ) && in_the_loop() ) {
                $title = "Deine Bezahlmethoden";  
            }
            elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
                $title = "Dein Nutzerkonto"; 
            }
            return $title;
        }
        add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 ); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM