[Fixed] Optional Postal Code is not working

Hi there! Magento provides us a very flexible way to exclude postal code in customer address. It can be done easily in the backend. You just need to go to System > Configuration > General. In Countries Options tab, you can select countries which you don't need postal code. However, the problem is that it does not actually work.


In frontend, when checking out, you still have to enter postal code in billing address field.


Let's see how to fix this issue. What you need is to rewrite this class "Mage_Eav_Model_Attribute_Data_Text". You can create your own module to rewrite it or try to copy it to local folder. You will need to change "validateValue" function. In this post, I rewrote this function in my own file.

class Magebuzz_Custommodule_Model_Customer_Attribute_Data_Text extends Mage_Eav_Model_Attribute_Data_Text {
	public function validateValue($value) {
		$attribute  = $this->getAttribute();	

		if ($attribute->getAttributeCode() == 'postcode') {
			$countryId = $this->getExtractedData('country_id');
			$optionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
			if (!in_array($countryId, $optionalZip)) {
				return parent::validateValue($value);
			return true;
		else {
			return parent::validateValue($value);

3 thoughts on “[Fixed] Optional Postal Code is not working”

3 Responses to [Fixed] Optional Postal Code is not working