6

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.