How to remove the phone field from the customer account settings or make it optional in Magento

In this article we'll show you how to remove the phone field from the frontend account settings of registered customers or how to make it an optional field instead of a required one. After registered customers log in to their account on your Magento site they can edit and add addresses from the Address Book section of their account settings. By default, there's a telephone field which is required and so the customer cannot add/edit an address without specifying a phone number. With a few modifications you can remove the field from the customer account settings or make it an optional one.

This is done in a similar way as removing or making optional the phone field on the checkout page. For more information on this subject read the Magento article on removing the telephone setting from the checkout page or making it an optional one.

As with the checkout page you need to edit the file Abstract.php. If, for example, your Magento is installed directly in the public_html folder on your Magento hosting account, the path to the file will be public_html/app/code/core/Mage/Customer/Model/Address/Abstract.php. In case you haven't done it so far you need to comment out the code:

if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
 $errors[] = Mage::helper('customer')->__('Please enter the telephone number.');

To comment it out put a forward slash and an asterisk at the beginning (e.g. /*) and an asterisk and a forward slash at the end of the code (e.g. */).

You also need to make a change in the database in which your Magento is installed. You can achieve this using phpMyAdmin. You can access phpMyAdmin using the link in the black area on the right in the Databases section of the Pixie control panel. In phpMyAdmin find the database of your store in the left frame and click on its name. Then in the right frame find the table magento_eav_attribute (magento should be replaced with the actual table prefix of your database) and click on its name. On the next page find the row that has telephone for attribute_code value and click on the Edit button corresponding to that row. On the following page change the value for is_required from 1 to 0, and click on the Go button at the bottom.

Whether you want to remove or make optional the phone field in the customer settings, on the checkout page, or on both you need to make the change in the Abstract.php file and in the database.

Then you need to modify the file edit.phtml. If you use the default theme that comes prepackaged with Magento and public_html is the root Magento folder, the path to the file will be public_html/app/design/frontend/base/default/template/customer/address/edit.phtml. In the file find the following code (around line 57):

<div class="field">
<label for="telephone" class="required">
<em>*</em><?php echo $this->__('Telephone') ?></label>
<div class="input-box">
<input type="text" name="telephone" 
value="<?php echo $this->
escapeHtml($this->getAddress()->getTelephone()) ?>" 
title="<?php echo $this->__('Telephone') ?>" class="input-text  
<?php echo $this->helper('customer/address')->
getAttributeValidationClass('telephone') ?>" 
id="telephone" />

To remove the field comment it out by putting an exclamation mark and two hyphens after the first bracket (e.g. <!--div class) and two hyphens before the last one (e.g. /div-->). If you want to make the field optional, don't comment out the code but just comment out or delete the part <em>*</em>, so that the red asterisk that marks the field as a required one is removed from the frontend. You can edit the file from the Files section of the Pixie control panel. Alternatively, you can download it on your local computer with an FTP client (e.g. FileZilla), edit it with a text editor (e.g. Notepad) and upload it back overwriting the old file.

When it comes to modifying core files such as Abstract.php it's preferable to override them. For more information on this read the article on overriding core Magento files. If you don't want to modify the original template files of the theme, you can use a subtheme. For more information check out the article on creating a child theme in Magento.

In case you want to remove other fields from the address form of the customer account settings you may find interesting the articles:

Was this answer helpful?

 Print this Article

Also Read