简体   繁体   English

如何在 WooCommerce 中更改我的所有帐户端点 url

[英]How to change all my account endpoints urls in WooCommerce

I'm using Woocommerce Version 4.8.0 I have a problem with my account page I want to change all the URLs like the image down below:我正在使用 Woocommerce 版本 4.8.0 我的帐户页面有问题 我想更改所有 URL,如下图所示:

网址

I have found on stackoverflow the solution for it but the code change only one URL not all of them我在 stackoverflow 上找到了它的解决方案,但代码只更改了一个 URL 而不是全部

add_filter('woocommerce_get_endpoint_url', 'woocommerce_hacks_endpoint_url_filter', 10, 4);
function woocommerce_hacks_endpoint_url_filter($url, $endpoint, $value, $permalink) {
    $downloads = get_option('woocommerce_myaccount_downloads_endpoint', 'downloads');
    if (empty($downloads) == false) {
        if ($endpoint == $downloads) {
            $url = '//example.com/customer-area/dashboard';
        }
    }
    return $url;
}

Any help?有什么帮助吗?

All related endpoints slugs can be found on WooCommerce settings > Advanced (tab) > Account endpoints:所有相关的端点 slug 都可以在 WooCommerce 设置 > 高级(选项卡) > 帐户端点上找到:

在此处输入图像描述

Then you can use a switch statement to change the required account endpoints URLs as follows:然后,您可以使用 switch 语句更改所需的帐户端点 URL,如下所示:

add_filter('woocommerce_get_endpoint_url', 'change_my_account_endpoint_urls', 10, 4);
function change_my_account_endpoint_urls( $url, $endpoint, $value, $permalink ) {
    switch($endpoint){
        case 'orders':
            $url = home_url('/customer-area/the-orders/');
            break;
        case 'downloads':
            $url = home_url('/customer-area/the-downloads/');
            break;
        case 'edit-address':
            $url = home_url('/customer-area/the-edit-address/');
            break;
        case 'edit-account':
            $url = home_url('/customer-area/new-edit-account/');
            break;
        case 'payment-methods':
            $url = home_url('/customer-area/the-payment-methods/');
            break;
    }
    return $url;
}

Code goes in functions.php file of the active child theme (or active theme).代码进入活动子主题(或活动主题)的functions.php文件。 Tested and works.测试和工作。

To change the My account URL itself, you need to edit the my account page in backend and change its permalink (editing the URL slug).要更改我的帐户 URL 本身,您需要在后端编辑我的帐户页面并更改其永久链接(编辑 URL slug)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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