如何更改 WooCommerce 我的帐户页面标题?

Bre*_*ett 1 php account wordpress woocommerce hook-woocommerce

我想更改 WooCommerce 我的帐户部分中每个页面的页面标题(条目标题),以便它们与您所在的实际页面相关,而不是在每个页面上输出通用的“我的帐户”。

我环顾四周,在几个地方看到了这个解决方案:

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 );
Run Code Online (Sandbox Code Playgroud)

这并不会,除非你删除的工作in_the_loop检查,这显然不是理想的,因为那么它最终在页面上改变其他的一些东西。

然后我找到了这个答案,例如如何更改“帐户详细信息”页面的标题:

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;
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用,它甚至似乎根本没有进入该功能。

有没有办法做到这一点,实际上有效?

Loi*_*tec 5

更改主我的帐户页面标题和我的帐户页面标题子部分:

1) 对于“我的帐户:dashbord (主页)

要更改主“我的帐户”页面标题,您只需要直接更改后端页面的标题,因为它不是端点,并检查Settings>Advanced部分页面(具有重命名的标题)仍然分配给“我的帐户页面”。

在此处输入图片说明


在此处输入图片说明


2) 对于“我的帐户”部分中的其他“端点”页面标题:

使用woocommerce_endpoint_{$endpoint}_title 复合专用过滤器钩子,其中{$endpoint}需要由目标端点替换(请参阅Settings>Advanced部分上的可用端点)

示例:要更改我的帐户“订单”端点页面标题,您将使用:

add_filter( 'woocommerce_endpoint_orders_title', 'change_my_account_orders_title', 10, 2 );
function change_my_account_orders_title( $title, $endpoint ) {
    $title = __( "Your orders", "woocommerce" );

    return $title;
}
Run Code Online (Sandbox Code Playgroud)

代码位于活动子主题(或活动主题)的 function.php 文件中。测试和工作。

在此处输入图片说明

如果它不起作用,那是因为其他东西在制造麻烦,例如您自己的自定义、主题的自定义、插件或其他东西……


相关的 StackOverFlow 答案: