Disable or make read only the fields from edit account pages in Woocommerce Disable or make read only the fields from edit account pages in Woocommerce wordpress wordpress

Disable or make read only the fields from edit account pages in Woocommerce


Update

For edit "Account details" fields (email field), you will need to edit myaccount/form-edit-account.php template file as those fields are hard coded in the template

You will have to add a readonly attribute to the related input fields like in this extract example:

<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
    <label for="account_first_name"><?php esc_html_e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>    <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="account_first_name" id="account_first_name" autocomplete="given-name" value="<?php echo esc_attr( $user->first_name ); ?>" readonly /></p>

Official documentation: Overriding templates via a theme

For My account > edit billing address, the following code will make readonly the billing fields first name, last name and email:

add_filter( 'woocommerce_billing_fields', 'readonly_billing_account_fields', 25, 1 );function readonly_billing_account_fields ( $billing_fields ) {    // Only my account billing address for logged in users    if( is_account_page() ){        $readonly = ['readonly' => 'readonly'];        $billing_fields['billing_first_name']['custom_attributes'] = $readonly;        $billing_fields['billing_last_name']['custom_attributes'] = $readonly;        $billing_fields['billing_email']['custom_attributes'] = $readonly;    }    return $billing_fields;}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Note: To enable that on checkout page too, Just remove if( is_account_page() ){ and the closing bracket } before return $billing_fields;.


To remove those 3 fields you will use:

add_filter( 'woocommerce_billing_fields', 'remove_billing_account_fields', 25, 1 );function remove_billing_account_fields ( $billing_fields ) {    // Only my account billing address for logged in users    if( is_account_page() ){        unset($billing_fields['billing_first_name']);        unset($billing_fields['billing_last_name']);        unset($billing_fields['billing_email']);    }    return $billing_fields;}

Code goes in function.php file of your active child theme (or active theme). Tested and works.


You can easily disable various fields from the WooCommerce Account Page by adding this to your theme's functions.php

function my_remove_checkout_fields($fields) {    unset( $fields ['billing'] ['billing_first_name'] );    unset( $fields ['billing'] ['billing_last_name'] );    unset( $fields ['billing'] ['billing_email'] );    // Any other fields you want to unset...    return $fields;}add_filter( 'woocommerce_checkout_fields', 'my_remove_checkout_fields' );

The documentation for customizing fields can be found here.