Jump to content

Make phone number when registering NOT compulsory


Recommended Posts

To do this you need to edit the AuthController.php file. Assuming your PrestaShop is installed directly in the public_html directory on your hosting account, the path to the file would be public_html/controllers/AuthController.php. To make the phone fields optional you have to delete or comment out the following code:

 

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

You can comment it out by putting a forward slash and an asterisk (e.g. /*)at the beginning of the code, and an asterisk and a forward slash (e.g. */) at the end of the code.

 

In case you want to remove the text You must register at least one phone number and the red asterisk from the registration form, you have to edit the authentication.tpl file of the theme you're using. If you're using the default prestashop theme and your application is installed directly in the public_html directory on your hosting account, the path to the file would be public_html/themes/prestashop/authentication.tpl. Find 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" class="text" name="phone" id="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{/if}" />
 </p>
 <p class="text">
  <label for="phone_mobile">{l s='Mobile phone'}</label>
  <input type="text" class="text" name="phone_mobile" id="phone_mobile" value="{if isset($smarty.post.phone_mobile)}{$smarty.post.phone_mobile}{/if}" />
 </p>

 

To remove only the text and the red asterisk delete just the string:

 

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

In case you want to remove the fields altogether, just delete or comment out the whole thing. You can comment it out by putting an exclamation mark and two hyphen after the first bracket of the code (e.g. <!--p style), and two hyphens before the last bracket of the string of code (e.g. /p-->).

 

The whole thing described above will work for the registration process. However, when a customer logs in and wants to add a new address, for example, a phone number will still be required. To make it optional in the user account settings you need to edit the AddressController.php file. It's in the same folder as the AuthController.php file (e.g. public_html/controllers/AddressController.php). You need to delete or comment out the same piece of code as in the AuthController.php file.

 

If you want to remove the text You must register at least one phone number from the user account settings (or the phone fields altogether), you need to edit the file address.tpl of the theme you're using (example path: public_html/themes/prestashop/address.tpl). The code that you need is almost the same as in authentication.tpl. Repeat the same procedure, depending on whether you want to remove just the text or the fields.

 

Don't forget that when you edit template files, you have to enable the Force Compile option, so that you can see the changes on the frontend. You can do this from the back office of your PrestaShop (Preferences tab>Performance sub-tab). After you're done disable the force compile.

 

I hope I'm not forgetting something, and hope this helps.

  • Like 2
Link to comment
Share on other sites

  • 8 months later...

Thanks for the guide.

 

Considering how many people want to hide certain fields and make them mandatory / not mandatory, I figured by now they would have made this user configurable. It's a real pain having to do this via code.

Link to comment
Share on other sites

×
×
  • Create New...