Ask SkyVerge

This Ask SkyVerge question comes from Bojan:

I have a WC catalog site dedicated to a closed user (buyers) group only, so no unknown people can register. All users are preregistered by admin and no free registration is available.

Now I need to find the way to remove the buyers ability to edit their data, everything except maybe First/Second name. All the other fields (Company, Address etc.) should be read only. Is this possible?


We can definitely remove the ability to edit addresses while maintaining the ability to edit names / passwords. Even better, we can do so without overriding the “My Addresses” template (though this is another possible way to solve the problem).

Today we’ll look at how to remove the “Edit” link from the WooCommerce customer account account page. This way, customers cannot edit billing or shipping address details, but can still change names and passwords as desired.

By default, the customer account page shows “Edit” links with the customer Billing and Shipping addresses.

WooCommerce My Account Page

We’ll want to remove this edit link so customers cannot change their billing and shipping data. We can, however, leave in the link to edit the rest of the account details, such as name and password.

Remove “Edit” Address Links from My Account

The “My Address” template is what generates the billing and shipping addresses in the account section. The “Edit” link for these addresses is hard-coded into this template, so we can’t remove it with a filter.

We could override this template to remove it, but we can easily remove HTML elements via jQuery, so I’m going to opt to do this instead. As both of these edit links have the CSS class “edit”, I can target both with one statement.

// Remove "Edit" links from My Account > Addresses
function sv_remove_edit_account_links() {
    wc_enqueue_js( "
        jQuery(document).ready(function() {
            jQuery( 'a.edit' ).remove();
        });
    " );
}
add_action( 'woocommerce_after_my_account', 'sv_remove_edit_account_links' );

This tiny snippet will remove the “Edit” links for both the billing and shipping addresses, removing the customer’s ability to do so from the My Account page.

However, since I’m doing this, I also want to make another tiny change.

Change Account Welcome

The account “Welcome” message mentioned editing addresses in the My Account template. Since I’ve removed this ability, I probably want to adjust this wording a bit. We can easily use the Say What plugin, or can use the gettext filter to translate this text.

We’ll change this text to remove the mention of managing shipping and billing addresses.

// Change the "My Account" welcome text
function sv_change_wc_account_welcome( $translated_text, $original_text, $domain ) {
    
    // bail if we're in the admin or not using a WooCommerce string
    if ( is_admin() || 'woocommerce' !== $domain ) {
        return $translated_text;
    }
    
    $text = 'From your account dashboard you can view your recent orders, manage your shipping and billing addresses and <a href="%s">edit your password and account details</a>.';

    if ( $text === $original_text ) {
        $translated_text = 'From your account dashboard, you can view your recent orders, shipping and billing addresses, and <a href="%s">edit your password and account details</a>.';
    }

    return $translated_text;
}
add_filter( 'gettext', 'sv_change_wc_account_welcome', 10, 3 );

Now once we’ve put these two snippets together, our account welcome message will be changed, and the “Edit” links will be removed for both customer addresses. This leaves the customer with the ability to edit the core account details like name, but not the addresses.

WooCommerce updated My Account Page

Updated My Account Page

Hope this helps Bojan!

Published by Beka Rice

Beka leads product direction for SkyVerge, focusing on new features for our plugins and Jilt. She spends a lot of time on research and interviews, but likes to write so she has an excuse to spend more time jamming out to anything from The Clash to Lady Gaga.

5 Comments

  1. Dear Beka,
    Thank you very much for the effort and for having time to deal with this issue. I’ll try your solution asap and get back with the results.
    Let me just say that it is great privilege for me to become related to the SkyVerge community and awesome people behind it.
    Thanks once again 🙂

  2. This doesn’t appear to work on my website, the edit buttons are still there after adding both snippets to my function php file. Any ideas?

  3. Hi! How to Remove Fields ( billing_address_2) from Woocommerce Edit Address Form ?

  4. Ditto, doesn’t seem to work for me when adding these to my functions.php.

  5. Hi there,

    Is there a way of only disabling/removing the country field when someone wants to edit the shipping address?

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.