up to date guide to remove telephone required field from checkout

Before 1.8.1 I'm not aware of any ways to make this work, you have to either override the abstract core class in the local code pool or rewrite every single child class (ugly, I know).

From 1.8.1 on, they introduced the event customer_address_validation_after. I got rid of the validation by using reflexion, even if I'm not too proud of it. Might not solve your problem, but I thought I'd post it anyway.

/**
 * Validate address ignoring phone-related errors
 *
 * Internally uses reflexion. Maybe not the most
 * efficient or clean implementation, but allows
 * this functionality to be implemented without
 * the need to rewrite 3 core classes.
 *
 * Listens to:
 * - customer_address_validation_after
 *
 * @param Varien_Event_Observer $observer Event observer
 */
public function validateAddress(Varien_Event_Observer $observer)
{
    /* @var $address Mage_Customer_Model_Address_Abstract */
    $address = $observer->getAddress();
    if (!$address) {
        return;
    }

    $prop = new ReflectionProperty('Mage_Customer_Model_Address_Abstract', '_errors');
    if (!$prop) {
        return;
    }
    $prop->setAccessible(true);
    $errors = $prop->getValue($address);
    $prop->setValue($address, array());

    $errorMessage = $this->getErrorMessage();
    foreach ($errors as $error) {
        if ($error !== $errorMessage) {
            $address->addError($error);
        }
    }
}

/**
 * Get standard error message
 *
 * @return string
 */
protected function getErrorMessage()
{
    return Mage::helper('customer')->__('Please enter the telephone number.');
}

I also wrote an update script to define the filed as not required, and edited all forms to remove the frontend validation. Like I said, it might not be the best solution, but it's better than rewriting 3-4 classes IMHO.

UPDATE The core team wrapped the event customer_address_validation_after in a conditional starting from 1.9.0 through 1.9.1.1 (I really wonder why, makes no sense to me...) so my solution won't work for these versions, unfortunately. The conditional was luckily removed in 1.9.2.


You will need to modify the Mage_Customer_Model_Address_Abstract class* on line 375-377 commenting the Zend Validation of the phone number.

//if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
//   $errors[] = Mage::helper('customer')->__('Please enter the telephone number.');
//}

as well as the telephone attribute itself in the database removing the required class. This can be done with the following query

UPDATE `eav_attribute` SET `is_required` = 0 WHERE `attribute_code` = 'telephone';

This will take care of the frontend (Javascript) validation of the telephone fields.

**Make sure to copy the class file to your local code directory*


I would suggest to change the address template for the site theme and make the phone a hidden field with as default value a space or dash. This will require no rewrites/overwrites.

Tags:

Checkout