Removing checkout fields in OpenCart

Note: This guide was written for OpenCart 1.x. Although the process is similar for OpenCart 2.x and 3.x, the actual code will differ from the one in this guide.

By default OpenCart asks your customers to specify a number of personal information and address fields during checkout. While this is suitable for most stores, sometimes you might want to simplify the checkout process by removing some fields from the checkout page.

The easiest way to do it is hide input fields and remove error checks. I'll use OpenCart as a basis, but this should be similar for all 1.5.x versions. We recommend you only modify OpenCart core files through vQmod or OCMOD.

Step 1: Modifying the template

There are two main templates responsible for input fields during checkout in default OpenCart theme: catalog/view/theme/default/template/checkout/register.tpl for account registration and catalog/view/theme/default/template/checkout/guest.tpl for guest checkout. Both of the files follow a similar structure so the process for modifying guest checkout template will be the same as for new user registration.

There are also two possible ways of introducing modifications: either by changing the original templates (directly or with vQmod) or by modifying copies of templates and then pointing the controller to load your new files. I'll describe the second method since it reduces the number of core modifications which in turn will make it easier to upgrade later on. You can also change the original templates if you wish - the process will be the same.

First, let's copy our original template: catalog/view/theme/default/template/checkout/register.tpl to catalog/view/theme/default/template/checkout/register-new.tpl.

This alone won't make OpenCart use our new template, we also need to tell the controller to use it instead of the original. In catalog/controller/checkout/register.php, find the following lines (145 - 149):

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/register.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/register.tpl';
} else {
$this->template = 'default/template/checkout/register.tpl';

Change register.tpl to register-new.tpl to tell the controller to load your new template. If you are using a custom theme, make sure you have the new file in your theme's folder.

Now you should be able to see the changes you make to register-new.tpl on the checkout page when selecting to create a new account. Let's make the changes!

We need to hide the input fields we don't want to be displayed by applying style="display:none" to them and removing the corresponding labels. Let's say we don't need Telephone, Fax, Company and Postcode fields.

First we remove the following lines of code from register-new.tpl:

<span class="required">*</span> <!--?php echo $entry_telephone; ?-->
<!--?php echo $entry_fax; ?-->
<!--?php echo $entry_company; ?-->
<span class="required">*</span> <!--?php echo $entry_postcode; ?-->

Now we need to hide the input fields by applying style="display:none":

<input class="large-field" style="display: none;" name="telephone" type="text" value="" />
<input class="large-field" style="display: none;" name="fax" type="text" value="" />
<input class="large-field" style="display: none;" name="company" type="text" value="" />
<input class="large-field" style="display: none;" name="postcode" type="text" value="" />

You can also remove the input fields instead of hiding them, however, you'll need to make sure they don't get accessed in the controller or you'll get a bunch of "Undefined index" notices later.

If you now refresh the page, you'll see that the input fields are gone (remove unnecessary line breaks to align the fields properly). However, the new checkout won't work yet. We now have to make appropriate changes in the controller to remove unnecessary validation of hidden fields.

Step 2: Modifying the controller

Controllers reponsible for checkout screen validation are catalog/controller/checkout/register.php for account registration and catalog/controller/checkout/guest.php for guest checkout. As with templates, they have a similar structure so I'll only describe modification of the first one.

All input form validation begins on line 18, when a post request gets submitted to the controller. Since Company and Fax are not mandatory inputs, we will comment out error checks for the rest of our fields: Telephone and Postcode. You can either comment out whole blocks or just the lines where the error variables get set.

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
//$json['error']['telephone'] = $this->language->get('error_telephone');
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['postcode']) < 2) || (utf8_strlen($this->request->post['postcode']) > 10)) {
//$json['error']['postcode'] = $this->language->get('error_postcode');

Basically, this is it: our input fields are hidden, so empty values will get passed to the controller. However, since HTML forms can be altered on client side, we want to be sure no one tries to post any values for our removed input fields from a modified form, so we'll explicitly clear post array values for both fields before the validation begins. If you removed the fields instead of hiding them, doing this will also ensure you don't get "Undefined index" notices:

if ($this->request->server['REQUEST_METHOD'] == 'POST') {
if (!$json) {
$this->request->post['telephone'] = '';
$this->request->post['postcode'] = '';

Now we're done! Our customers don't have to enter their telephone number and postcode anymore and the company input field is removed from the form.

Need help? Hire us!

We offer a wide range of professional OpenCart & MultiMerch services. Find out more!

checklist 500

Download our free Marketplace Cheat Sheet

Find out what it takes to start a successful online marketplace.

Martin Boss

Martin is the founder of MultiMerch, an ex-OpenCart developer and an e-commerce enthusiast.You can also find him on LinkedIn, Twitter and Quora.