Removing checkout fields in OpenCart

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 1.5.1.3 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):

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:

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

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.

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:

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.

Download

Download checkoutFields.zip, put the two files in the appropriate locations and try it yourself! This download contains a vQmod xml file to do all needed modifications so you'll need vQmod.