Knowledgebase

How to make optional or remove the phone fields from the customer account settings in PrestaShop

Once users are registered they can add new addresses and edit existing ones. They can do this from their account settings after they log in. This also means that they can add and edit the phone numbers associated with these addresses. If you want to, you can make the phone fields on the address form of the customer account settings optional, or you can completely remove them. This is done in a different way depending on the PrestaShop version. Check out the section in this article that's relative to the version of your PrestaShop:

For information on how to do this on the registration form check out the article on removing or making optional the phone fields on the registration page in PrestaShop.

PrestaShop versions older than 1.5

When it comes to versions older than PrestaShop 1.5 you have to make code changes in order to make optional or remove the phone fields from the customer account settings. Keep in mind that even if the phone fields are not required and are removed from the registration page, they will still be required when a registered user tries to add a new address or change an existing one from the My Addresses section of their account settings. The code modifications that have to be made for the registration page and for the account settings are different. Whether the phone fields are required, optional or removed from the registration page you can still make them optional or remove them completely from the address form of the customer account settings.

In both cases the first thing that you should do is to edit the file AddressController.php. Assuming that your PrestaShop is installed directly in the public_html folder on your PrestaShop hosting account, then the path to the file would be public_html/controllers/AddressController.php. You can edit the file from the Files section of the Pixie control panel. Another way to do it is to download it with an FTP client (e.g. FileZilla), edit it with a text editor (e.g. Notepad, Wordpad), and upload it back overwriting the old file. The code that you should delete or comment out looks like this:

if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile'))
$this->errors[] = Tools::displayError('You must register at least one phone number');

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

Modifying the AddressController.php file in such a way will make the phone fields on account settings page optional. So users can add phone numbers if they want to, but they will be able to add a new address or edit an existing one without specifying a phone number.

If you want to, you can remove the phone fields so that they are not visible in the account settings. So to do this, after you make the above change you need to modify the address.tpl file of the theme that you use. For example, if your PrestaShop is installed directly in the public_html folder on your hosting account and you use the theme prestashop, the path to the file would be public_html/themes/prestashop/address.tpl. Delete or comment out the following code:

<p style="margin-left:50px;">{l s='You must register at least one phone number'} 
<sup style="color:red;">*</sup></p>
<p class="text">
<label for="phone">{l s='Home phone'}</label>
<input type="text" id="phone" name="phone" value="{if isset($smarty.post.phone)}
{$smarty.post.phone}{else}{if isset($address->phone)}
{$address->phone|escape:'htmlall':'UTF-8'}{/if}{/if}" />
</p>
<p class="text">
<label for="phone_mobile">{l s='Mobile phone'}</label>
<input type="text" id="phone_mobile" name="phone_mobile" 
value="{if isset($smarty.post.phone_mobile)}{$smarty.post.phone_mobile}{else}
{if isset($address->phone_mobile)}
{$address->phone_mobile|escape:'htmlall':'UTF-8'}{/if}{/if}" />
</p>

To comment it out put an exclamation mark and two hyphens after the first bracket of the string (e.g. <!--p style), and two hyphens before the last bracket (e.g. p-->).

In case you want to make the phone fields optional and leave them displayed so that users can add phone numbers if they want to, delete or comment out only the code:

<p style="margin-left:50px;">{l s='You must register at least one phone number'} 
<sup style="color:red;">*</sup></p>

When you edit template files such as address.tpl you should enable the Force Compile option. In this way you'll be able to see the change when you refresh the frontend of your site. You can enable the force compile from the back office of your PrestaShop (Preferences tab>Performance sub-tab). After you make sure that the changes are visible on the frontend disable the force compile.

Don't forget that changes to the code of core files are overwritten during and upgrade of the application. It's advisable to keep track of all the changes you make.

For information on how to make optional or remove the phone fields from the registration form check out the article on removing the phone fields from the registration form in PrestaShop.

PrestaShop 1.5 and newer versions

PrestaShop 1.5 and newer versions have built-in options for making the phone fields optional. Log in to the admin panel of your PrestaShop and go to Preferences menu>Customers. Set the option Phone number to No and save the change. This will make the phone fields on the address form in the customer account settings optional (it will also make them optional on the registration form for new customers).

If you want to remove them altogether, in addition to setting the Phone number option to No you also have to make one minor code modification. You need to modify the file address.tpl of the theme that you use. If you use the default theme that comes prepackaged with PrestaShop 1.5 and the application is installed directly in the public_html directory on your PrestaShop hosting account, then the path to the file will be public_html/themes/default/address.tpl. The default theme that comes prepackaged with PrestaShop 1.6 is in a folder labeled default-bootstrap so the path to it will be respectively public_html/themes/default-bootstrap/address.tpl.

In the file itself you need to comment out some code. The exact code depends on the theme you use. But it would be similar to the examples we'll give here. They are from the default themes of PrestaShop 1.5 and 1.6. The exact code in the default themes might differ not only between major versions, but also between releases within a version. For example, the code in PrestaShop 1.5.3 may be different than that in PrestaShop 1.5.6. The line numbers that we have given may also differ depending on the version.

In PrestaShop 1.5 the code for the home phone number in the address.tpl file of the default theme is (around line 231):

<p class="text">
<label for="phone">{l s='Home phone'}</label>
<input type="text" id="phone" name="phone" value="{if isset($smarty.post.phone)}
{$smarty.post.phone}{else}{if isset($address->phone)}{$address->phone}{/if}{/if}" />
</p>

And exactly after it is the code for the mobile phone number (around line 235):

<p class="{if isset($one_phone_at_least) && $one_phone_at_least}required {/if}text">
<label for="phone_mobile">{l s='Mobile phone'}
{if isset($one_phone_at_least) && $one_phone_at_least} 
<sup>*</sup>{/if}</label>
<input type="text" id="phone_mobile" name="phone_mobile" 
value="{if isset($smarty.post.phone_mobile)}{$smarty.post.phone_mobile}{else}
{if isset($address->phone_mobile)}{$address->phone_mobile|escape:'html'}{/if}{/if}" />
</p>

In the address.tpl file of the default theme of PrestaShop 1.6 the code for the home phone number is (around line 130):

<div class="form-group phone-number">
<label for="phone">{l s='Home phone'}
{if isset($one_phone_at_least) && $one_phone_at_least} 
<sup>**</sup>{/if}</label>
<input class="{if isset($one_phone_at_least) && $one_phone_at_least}is_required{/if} 
validate form-control" data-validate="{$address_validation.phone.validate}" type="tel" 
id="phone" name="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{else}
{if isset($address->phone)}{$address->phone|escape:'html':'UTF-8'}{/if}{/if}"  />
</div>

And a few lines under it is the code for the mobile phone number (around line 142):

<div class="{if isset($one_phone_at_least) && 
$one_phone_at_least}required {/if}form-group">
<label for="phone_mobile">{l s='Mobile phone'}
{if isset($one_phone_at_least) && $one_phone_at_least} <sup>**</sup>{/if}</label>
<input class="validate form-control" 
data-validate="{$address_validation.phone_mobile.validate}" 
type="tel" id="phone_mobile" name="phone_mobile" 
value="{if isset($smarty.post.phone_mobile)}
{$smarty.post.phone_mobile}{else}{if isset($address->phone_mobile)}
{$address->phone_mobile|escape:'html':'UTF-8'}{/if}{/if}" />
</div>

Note that with the default PrestaShop 1.6 theme there are a couple of places in the file where there's code for the phone numbers. You should comment out the code that's closer to the beginning of the file.

You can comment code out by putting an exclamation mark and two hyphens after the first bracket of the string of code (e.g. <!--p class) and two hyphens before the last one (e.g. /p-->). You can comment out the code for both phone fields or just for one of the two, depending on which field you want to remove. This can be done from the Files section of the Pixie control panel. Alternatively you can download the file with an FTP client, edit it with a text editor (e.g. Notepad, Wordpad) and upload it back replacing the old file.

For information on how to remove the phone fields from the registration form check out the article on removing the phone fields from the registration form in PrestaShop.

Was this answer helpful?

 Print this Article

Also Read