Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies

Sunday, June 23, 2013

Magento: Disable state/province option in checkout onepage

Sometime you want to remove the state/province option in the checkout onepage. Please do as following steps  Magento versions (up to Magento CE 1.7)
You have to edit 4 files:
- /checkout/onepage/shipping.phtml
- /checkout/onepage/billing.phtml
- app/core/Mage/Customer/Model/Adress/Abstract.php
-/skin/frontend/default/default (or your skin)/js/opcheckout.js
billing.phtml:
Comment out this Part:
01
02
03
04
05
06
07
08
09
10
11
<div><code> <div class="input-box">
 <label for="billing:region"><?php echo $this->__('State/Province') ?> <span class="required">*</span></label><br/>
 <select id="billing:region_id" name="billing[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none">
 <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
 </select>
 <script type="text/javascript">
 $('billing:region_id').setAttribute('defaultValue'"<?php echo $this->getAddress()->getRegionId() ?>");
 </script>
 <input type="text" id="billing:region" name="billing[region]" value="<?php echo $this->htmlEscape($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none" />
 </div> </code></div>
<div>
shipping.phtml
The same:
1
2
3
4
5
6
7
8
9
<div><code> <div class="input-box">
 <label for="shipping:region_id"><?php echo $this->__('State/Province') ?> <span class="required">*</span></label><br />
 <select id="shipping:region_id" name="shipping[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none">
 <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
 </select>
 <script type="text/javascript">
 $('shipping:region_id').setAttribute('defaultValue'"<?php echo $this->getAddress()->getRegionId() ?>");
 </script>
 <input type="text" id="shipping:region" name="shipping[region]" value="<?php echo $this->htmlEscape($this->getAddress()->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none" /></div></code></div>
Abstract.php
Comment out:
1
2
3
4
5
<div><code> if ($this->getCountryModel()->getRegionCollection()->getSize()
 && !Zend_Validate::is($this->getRegionId(), 'NotEmpty')) {
 $errors[] = $helper->__('Please enter state/province.');
 } </code></div>
<div>
opcheckout.js
There are a few code-blocks you have to comment out.
Around line 330:
1
2
3
4
<div><code> if (window.billingRegionUpdater) {
 billingRegionUpdater.update();
 }</code></div>
<div>
Around line 440:
1
2
3
4
<div><code> shippingRegionUpdater.update();
 $('shipping:region_id').value = $('billing:region_id').value;
 $('shipping:region').value = $('billing:region').value;
 //shippingForm.elementChildLoad($('shipping:country_id'), this.setRegionValue.bind(this)); </code></div>
Around line 450:
1
2
3
4
<div><code> setRegionValue: function(){
 $('shipping:region').value = $('billing:region').value;
 },</code></div>
<div>
Around line 490:
1
2
3
4
<div><code> if (window.shippingRegionUpdater) {
 shippingRegionUpdater.update();
 } </code></div>
<div>

15 comments:

  1. Wow! Good suggestion is very useful for the good websites , also helping us for the success in the future. Good manage keep it up.
    Cado Magenge
    "http://appdevelopmentcompany.com.au/social-media-optimization.html"
    "http://www.appdevelopmentcompany.com.au/email-marketing.html"
    ”http://www.appdevelopmentcompany.com.au/iphone-application-development.html”
    ”http://www.appdevelopmentcompany.com.au/magento-development.html”

    ReplyDelete
  2. Sometimes store owners want to remove some states from Magento State/Region list during checkout step because they don't want to ship items to those states. Displaying such states is meaningless. It requires some coding changes. The following blog helped me achieve this.

    http://www.demagento.com/magento-how-to-remove-unwanted-states-from-stateregion-list-at-checkout/

    ReplyDelete
  3. Hey,
    In magento1.9 is not working what should I do?

    ReplyDelete
  4. I know this for magento 1.7

    ReplyDelete
  5. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    Python Online training
    python Training in Chennai
    Python training in Bangalore

    ReplyDelete