Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the URL of WooCommerce "My Account" menu in Wordpress?

I'm using WooCommerce plugin in Wordpress.

I would like to change the URL of the "Downloads" link that appears on "my-account" page created by WooCommerce.

enter image description here

I want to change it from linking to /my-account/downloads/ to /customer-area/dashboard/

I tried to add a custom function that changed the titles and endpoints of menu items.

function wpb_woo_my_account_order() {
    $myorder = array(
        'edit-account'       => __( 'Change My Details', 'woocommerce' ),
        'dashboard'          => __( 'Dashboard', 'woocommerce' ),
        'orders'             => __( 'Orders', 'woocommerce' ),
        'customer-area/dashboard' => __( 'Download MP4s', 'woocommerce' ),
        'edit-address'       => __( 'Addresses', 'woocommerce' ),
        'payment-methods'    => __( 'Payment Methods', 'woocommerce' ),
        'customer-logout'    => __( 'Logout', 'woocommerce' ),
    );
    return $myorder;
}
add_filter ( 'woocommerce_account_menu_items', 'wpb_woo_my_account_order' );

However, whatever endpoint I use, it remains nested inside /my-account/

How can I change that?

like image 879
Halnex Avatar asked Oct 13 '16 16:10

Halnex


1 Answers

The way I've done that in the past is to change the endpoint URL via the Woocommerce woocommerce_get_endpoint_url filter, like this:

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;
}

Obviously, change the $url variable to suit your environment. The reason we use the get_option() function is because you can change the endpoints in Woocommerce settings, which means downloads may not be your specific endpoint.

like image 168
Lutrov Avatar answered Sep 21 '22 17:09

Lutrov