0

I want to remove required field from city and make it non required field at checkout page. how can i implement this?

enter image description here

  • Why would "city" not be required? Isnt it a very useful field for invoice, shipping... Its part of the address, is there really a usecase where one have no city? – roman204 Oct 14 '17 at 6:11
  • @roman204 - there is some error in city field, city value does not save in customer address, it show error when place order again - city is a required field. – Aks Oct 14 '17 at 6:40
0

You can remove city as a required field from checkout page by customizing template file of billing & shipping address form.

In rwd theme of default Magento 1.9.3.6 you can customize below code in both template files.

For Billing Address form: app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml

Replace below code

<div class="field">
<label for="billing:city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->quoteEscape($this->__('City')) ?>" name="billing[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="billing:city" />
</div>
</div>

with

<div class="field">
<label for="billing:city"><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->quoteEscape($this->__('City')) ?>" name="billing[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text" id="billing:city" />
</div>
</div>

For Shipping Address form: app/design/frontend/rwd/default/template/checkout/onepage/shipping.phtml

Replace below code

<div class="field">
<label for="shipping:city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>" name="shipping[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="shipping:city" onchange="shipping.setSameAsBilling(false);" />
</div>
</div>

with

<div class="field">
<label for="shipping:city"><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>" name="shipping[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text" id="shipping:city" onchange="shipping.setSameAsBilling(false);" />
</div>
</div>

I hope this will useful to you.

Thanks

0

1- Remove the required class from following files in your theme folder.

checkout/onepage/shipping.phtml
checkout/onepage/billing.phtml
persistent/checkout/onepage/billing.phtml

<!--<label for="shipping:city" class="required"><em>*</em><?php echo $this->__('city') ?></label>-->
<label for="shipping:city"><?php echo $this->__('city') ?></label>

also remove classes from input field as-well

<?php //echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>

2- copy this core class to your local and remove following lines app/code/core/Mage/Customer/Model/Address/Abstract.php

/*if (!Zend_Validate::is($this->getcity(), 'NotEmpty')) {
  $this->addError(Mage::helper('customer')->__('Please enter the city number.'));
}*/

3- Change the attribute is_required in DB

update eav_attribute set is_required=0 where attribute_code='city';

Note: step three is a dirty hack, correct way would be creating an setup file in your custom extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.