OpenCart Remove Required Telephone on Checkout


On 02-26-2013 articles, code, web design

Ive been doing quite a few OpenCart customization sites lately. And one thing I always have to do is take out the required telephone field on the checkout page. I haven’t done it in a while, and well when I searched Google for the template pages to go to and find the code, it took me a good 10mins to find exactly what I was looking for.

So here is your guide to removing the required telephone field in OpenCart on checkout. 

Files that are throwing the errors if you don’t enter a phone number.
Catalog/Controller/Checkout/guest.php
Catalog/Controller/Checkout/register.php

First we have to turn off the warning when someone doesn’t enter a phone number. You will do this in both files listed above. You will need to find the json code. It changes from version to version of OpenCart, so a find (ctrl F) on your editor and search error_telephone and it should take you to the line you need to delete.

if ((utf8_strlen($this->request->post['telephone']) < 3) 
|| (utf8_strlen($this->request->post['telephone']) > 32)) {
                $json['error']['telephone'] = $this->language->get('error_telephone');
            }

Next we need to get rid of the astrix that says the field is required. So we edit the view files.

Catalog/View/Theme/YOURTHEMENAME/Template/Checkout/guest.tpl
Catalog/View/Theme/YOURTHEMENAME/Template/Checkout/register.tpl

These 2 files you are just removing the red astrix that states this a required field.

<span>*</span> <?php echo $entry_telephone; ?><br />

 

That’s it. Pretty simple, and can be applied to other fields.


Comments

  1. Matt says:

    Would just like to say thank-you for this page. You were the first site that came up when searching for a way to remove this feature and the guide on doing so was so simple and easy. So thanks again and keep up the good work!!

    • craig says:

      No problem Matt, it was my hope I would rank high so others could find the simple solution instead of wadding through all the sites that are over complicated or don’t tell you what you need to know.