Knowledgebase

How to remove the ZIP/Postcode field from the checkout page in Magento

At the billing address and shipping address steps of the checkout process in Magento the field for zip/postcode is required by default. If you want to remove it so that customers can place orders without specifying a postcode, you have to make a few code modifications.

First, let's start with removing the field from being displayed on the checkout page. To do this you need to edit three files by commenting out some code in them. Let's assume that your Magento is installed directly in the public_html folder on your Magento hosting account, meaning that the frontend is accessible at yourdomain.com.

Then on your hosting account you need to go to public_html/app/design/frontend/base/default/template/checkout/onepage/billing.phtml. This path is to the billing.phtml file of the default theme that comes prepackaged with Magento; if you use another theme you may need to edit the file of that theme. In the billing.phtml file find and comment out the following code (around line 105):

<div class="field">
<label for="billing:postcode" class="required"><em>*</em>
<?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" 
name="billing[postcode]" id="billing:postcode" 
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" 
class="input-text validate-zip-international <?php echo $this->
helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
</div>

To comment it out put an exclamation mark and two hyphens after the first bracket (e.g. <!--div) and two hyphens before the last one (e.g. /div-->). You can edit the file from the Files section of the Pixie control panel. Another way is to download the file on your local computer with an FTP client (e.g. FileZilla), edit it with a text editor (e.g. Notepad, Wordpad) and upload it back in the same folder on your hosting account overwriting the old file.

After that edit the file public_html/app/design/frontend/base/default/template/checkout/onepage/shipping.phtml and comment out the code (around line 96):

<div class="field">
<label for="shipping:postcode" class="required"><em>*</em>
<?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" 
name="shipping[postcode]" id="shipping:postcode" 
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" 
class="input-text validate-zip-international 
<?php echo $this->helper('customer/address')->
getAttributeValidationClass('postcode') ?
>" onchange="shipping.setSameAsBilling(false);" />
</div>
</div>

You need to edit another billing.phtml file but in a different location. With public_html being the root Magento directory on your hosting account and with the default theme, the path to the file will be public_html/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml. In that file find and comment out the code (around line 106):

<div class="field">
<label for="billing:postcode" class="required"><em>*</em>
<?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" 
name="billing[postcode]" id="billing:postcode" value="<?php echo $this->escapeHtml
($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international 
<?php echo $this->helper('customer/address')->
getAttributeValidationClass('postcode') ?>" />
</div>
</div>

The above three modifications will visually hide the postcode field from being displayed on the checkout page on the frontend. However, since this is a required field you also need to disable the postcode validation. To do this you have to edit another file and make a minor change in the database. The file that you have to edit is Abstract.php. With public_html as the root Magento directory on your hosting account, the path to the file will be public_html/app/code/core/Mage/Customer/Model/Address/Abstract.php. Find and comment out the code (around line 380):

if (!in_array($this->getCountryId(), $_havingOptionalZip)
            && !Zend_Validate::is($this->getPostcode(), 'NotEmpty')
      ) {
         $errors[] = Mage::helper('customer')->__('Please enter the zip/postal code.');
        }

To comment out PHP code put a forward slash and an asterisk at the beginning (e.g. /*if) and an asterisk and a forward slash at the end (e.g. }*/).

The last thing to do is to perform one modification in the database in which your Magento is installed. You can do that with phpMyAdmin. You can access phpMyAdmin from the Databases section of the Pixie control panel (there's a link in the black area on the right). In phpMyAdmin find the database in the frame on the left and click on its name. The database tables will appear in the right frame. Find the table magento_eav_attribute (you should replace magento with the actual prefix of your database tables). If there are no other applications in the same database, the table magento_eav_attribute should be on the first page (there are drop-down menus at the top and bottom of the page with which you can switch between pages). Click on the edit button of the magento_eav_attribute table; this will display its rows. Find the row that has postcode for attribute_code and click on its edit button. On the following page change is_required from 1 to 0 and click on the Go button at the bottom of the page.

Now you can test the result on the frontend of your site.

If you also want to remove the postcode field from the frontend customer account settings, you can do that by modifying another file (in addition to the database change and the modification to the Abstract.php file). For more information read the article on removing the ZIP/Postcode field from the frontend customer account settings in Magento.

It's not recommended to modify core files because the changes get overwritten when you upgrade the application. If you want to find out how to override core PHP files such as Abstract.php, read the article on overriding core files in Magento. To avoid changing the core files of the theme you can create a subtheme and perform the modifications to the subtheme. To learn how to do that check out the article on creating a subtheme in Magento.

When it comes to removing or making optional fields on the checkout page you may also find interesting the following articles:

Was this answer helpful?

 Print this Article

Also Read