简体   繁体   中英

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:

网址

I have found on stackoverflow the solution for it but the code change only one URL not all of them

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:

在此处输入图像描述

Then you can use a switch statement to change the required account endpoints URLs as follows:

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). 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).

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