Magento2: Telephone number on customer address shouldn't be required

Created on 17 Aug 2015  路  50Comments  路  Source: magento/magento2

Hi guys

Why is the telephone number still required on a customer address?
We hear from our shop owners that a lot of customers refuse to enter something in there or just enter gibberish.

An ideal solution would be if you could add a configuration option in the backend similar to the Gender, Tax/Vat Number and Date of Birth fields.
So an option for showing the telephone number where you can choose between No, Optional or Required. What do you think?

I had to implement this today into a Magento CE 1.x store and it was kind of a terrible experience, changing stuff in the database, remove the hard coded validation of that field (which is still present btw: https://github.com/magento/magento2/blob/93312cae42824274722fe7a285d5ce8e40f177a1/app/code/Magento/Customer/Model/Address/AbstractAddress.php#L572), ...

Related to https://github.com/magento/magento2/issues/624

Format is not valid Ready for Work feature request improvement

Most helpful comment

I have created a module which removes the requirement on the telephone input:
https://github.com/zsoerenm/magento2-optionaltelephone
It can be installed via composer

All 50 comments

Because vast majority of parcel services require it and for good reason -- they call first and make sure you're around as they lose money when they arrive behind your door only to find out that you're out for lunch.

Also there is a number of parcel point services that are not unlike PO boxes. For those phone number is actually the only required field (they send text message to let you know that your parcel have been arrived and you can pick it up whenever you're ready. The text also contains door code).

So .. I'm not against making this field optional, but it should depend on shipping method or something.

Ow ok, good to know, didn't realize this. I would need to check this with certain parcel services which are active over here, but I don't think most of them actually require a phone number (never heard about calling up front to somebody to make sure they are at home).

But a configuration to make it optional would be great then, if you don't use certain parcel services you can leave it optional, otherwise make it required, but this should be up to the shop owner to decide I believe, not from Magento to enforce this.

I guess the best way (pretty please, cherry on top?) would be that address attributes are shipping method specific. This however creates an interesting conundrum as parcel point service addresses are not compatible with courier service ones.

Anyone else wants to weight in?

It would be nice if there was some sort of explanation to the customer what
the number will be used for

example: Delivery Phone Number

I like idea to set up required phone number as option in configuration but feel uncertain about assignment of this option to shipping method. This leads to logical gap if you want to deliver to address without filled phone using shipping methods with mandatory phone.

I second the ability to make the phone number field either optional or required. Yes, some shipping couriers require it, but others do not and it becomes a potential for an abandoned cart. In the US, UPS/Fedex require a phone number, but as far as I know, I've never heard of them calling ahead. USPS does not require a phone number. When a customer does not provide a phone number, then usually the merchant puts in theirs. Some customers would prefer to only provide an email address.

Hi,

When a store sells only virtual products, the telephone is not required as there is no delivery.
So I think it is a good idea to make this field optional.

In some countries a telephone number is not required for shipping, but it drops the conversion rate. It is absolutely essential to disable the telephone number by need.

I have just started building my first M2 site and was shocked to find the telephone field could not be made optional in the admin.

Pretty fundamental, as has already been said if you're selling virtual products and I also think it's now illegal in Germany to force people to enter their phone number at the checkout.

Any eta when this will be fixed?

Because vast majority of parcel services require it and for good reason

@pronto2000 I'm not sure if there is a country for which this statement is true and if you are living in it but for most parts of the world this is bullshit (one of my clients ships worldwide and works with nearly all international and some national parcel services and none ever required a phone number).

I also think it's now illegal in Germany to force people to enter their phone number at the checkout

And yes, in Germany you can even get sued for it if you are selling products where it is not absolutely essential to get the phone number to fulfill the order. So basically 99% of German shops would face the risk of a pricy written warning with Magento this way.

Please give this some priority!

I agree on this. Phone numbers are not always necessary in specific situations and / or countries.
It is like state information and postal codes, some kind of configuration to make this mandatory would be really helpful.

I don't think so, phone number is required by default because it is the basic e-commerce or commerce workflow. How do the seller contact to buyer without any phone number?
This is also an avoid-abuse system, of course if the man who placed an order without any phone number, it is obviously abuse order and should be ignored.

I would have to disagree that someone placing an order without a phone number is obviously a fraudulent order and that there's no other way to contact a customer but by phone. A clear example would be in the industry that we're in which is adult products and where discretion is valued very highly. Not everyone wants to provide a phone number because they don't want to run the risk of getting called on their personal line about an intimate product.

Second, the most obvious way to contact a customer if they don't provide a phone number is via email; which almost all of our customers prefer. A good portion of phone numbers we are provided are obvious fake phone numbers; but we hardly receive fake email addresses. I can only imagine how many abandoned carts we're receiving due to the required phone number field and the sensitivity to providing that information in our industry.

@nntoan this is not how it works everywhere and in all industries.
No one says remove that field, we are just asking to get an option to make it optional. This way anyone can decide whether orders without phone numbers can be accepted or not.

Yes exactly. The telephone number should be optional. Here in Germany there is no need for this at all. Can someone point out how we make this field not a required field or how we can even delete it?

you can manipulate the data so its no longer required, the validation info is stored in customer_eav_attribute in the column validate_rules and the fact that the field is required is store in eav_attribute column is_required, you'll find the attribute by searching for the attribute_code telephone

here's the query
update eav_attribute set is_required=0 where attribute_code='telephone';

It is not so simple, in some files, the telephone validation is harcoded like here :
vendor/magento/module-customer/Model/Address/AbstractAddress.php, in function validate()

@ilol the first is really important to have an option here in the backend to 1. show the telephone number yes/no and 2. to have it as a required field yes/no - so anyone can decide.

I think it is a must must have (look at hundreds of posts in forums regarding this on magento1 and 2 now. :-/. The hole checkout is in my view very very hard to customize and takes ages to load especially on mobile devices. Also usability is not really well designed - but this is another topic.

we ended up overwriting a few classes via di.xml to change the behaviour, it's kind of all over the place though, there are 4-5 places you have to change

Could you explain more detail?

I can disable the Zend_validate but can't make sure about the JS

i want to add mobile sms otp in cash on delivery payment method in magento 2 i know otp code but i dont know how to get telephone number. or where to get telephone session telephone

Thanks and Regards

@ilol

If there is no chance to make this as an option in a magento release it would be great to have a documentation explaining how to delete tel. number or make it not a required field. Many people asked for this and i can not find any official documentation here. Can you pls provide this for the moment for us?

just a rough overview:
in di.xml we addressed:

  • <preference for="Magento\Sales\Model\Order\Address\Validator" type="Your\Module\Model\Order\Address\Validator" />
  • <preference for="Magento\Customer\Model\Address" type="Your\Module\Model\Address" />
  • <preference for="Magento\Quote\Model\Quote\Address" type="Your\Module\Model\Quote\Address" />
  • <preference for="Magento\Customer\Model\ResourceModel\AddressRepository" type="Your\Module\Model\ResourceModel\AddressRepository" />

in each instance we extended the original class and replaced the following methods:

  • \Magento\Sales\Model\Order\Address\Validator::validateForCustomer
  • \Magento\Quote\Model\Quote\Address::validate
  • \Magento\Customer\Model\ResourceModel\AddressRepository::_validate the method is private so you will have to implement a copy of this method and replace the save method instead, using your own _validateX method
  • \Magento\Customer\Model\Address::validate

database:

in the database we changed the telephone attribute required flag and removed the validation (not sure if the last part is necessary, maybe if someone enters a value you still want it validated)

my general observation implementing this using various approaches was, that the system is very cluttered in terms of where information is coming from, you got the attribute in the database, you got the layout.xml defining the javascript thats being rendered, you got the configprovider files where some properties are coming from as well and then you have the validators in several places. I feel like there should be single central point which defines what needs to be validated and how.

Thank you for your submission.

We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues.

Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here).

We are closing this GitHub ticket and have moved your request to the new forum.

Related: #6578
Initial issue was registered as MAGETWO-58099

@ilol can you put the same comment in the Forum post linked above.

its now over one year since this "issue" is reported. I still can not find any clean way to deactivate the tel. number from the checkout and user account.

Or is there a clean and working solution out there i do not know?

any update at all??

Discussing ETA with the development team.

ok - i give it up. if it takes more then one year to implement a highly needed function like making the telephone number not a required field i am out of this topic.

For me it feels like "bugs" and functions are discussed here over and over again but nothing happens. I do not like to know how many people from magento side and developers have spent time in reading this and finding a solution.
For the magento core team it should only be a view hours to implement this - but instead we are discussing more then a year and there is no easy way or solution on this.

Sry guys - but a shop system where you can not make the telephone field a not required field without a massive effort is a no go for me and my team.

Meanwhile some lines of mad JavaScript with timeouts, intervals and all the dirty stuff which simply needs to be thrown anywhere in the frontend to make the telephone number optional. (Yea, it doesn't make it optional from a technical point of view but fills in a pseudo value. However for the user it exactly behaves like the field is truly optional.)

Beware, this script might need adjustment for future Magento versions and _really_ implementing this feature officially would still be highly appreciated!

/**
 * Make the telephone in the checkout an optional value
 */
require(['jquery'], function($) {
    $(document).ready(function() {
        if ($('body.checkout-index-index').length) {
            function makeTelephoneOptional() {
                $('[name="billingAddresspurchaseorder.telephone"]').removeClass('required').removeClass('field _required').addClass('field');
                $('[name="shippingAddress.telephone"]').removeClass('required').removeClass('field _required').addClass('field');

                function fillEmptyTelephoneField(jQueryButtonElement) {
                    $('[name="telephone"]').each(function() {
                        var currentValue = $(this).val();
                        if (!currentValue) {
                            $(this).val("-keine Telefonnummer-").change();
                        }
                    });

                    window.checkoutPhoneOptional = true;
                    jQueryButtonElement.click();
                }

                $('button').off('.touchHandler');
                $('button').off('.clickHandler');
                $('button').on('touchstart.touchHandler click.clickHandler', function( event ) {
                    if (window.checkoutPhoneOptional) {
                        // trigger default event
                    } else {
                        event.preventDefault();
                        fillEmptyTelephoneField($(this));
                    }
                });

                // Don't view pseudo value
                try {
                    $('.billing-address-details').html($('.billing-address-details').html().replace("<!-- ko text: currentBillingAddress().telephone -->-keine Telefonnummer-<!-- /ko --><br>", "").replace("-keine Telefonnummer-", ""));
                } catch (e) {
                    // Not yet implemented
                }
            }

            makeTelephoneOptional();

            setInterval(function(){
                makeTelephoneOptional();
            }, 500);
        }
    });
});

I solved the problem with the following steps:

  1. Using sql query update eav_attribute set is_required=0 where attribute_code='telephone';
  2. Modified Magento\Sales\Model\Order\Address\Validator::validateForCustomer()
  3. Modified Magento\Customer\Model\ResourceModel\AddressRepository::_validate()
  4. Modified Magento\Customer\Model\Address\AbstractAddress::validate()

I think this approach is a true evidence of incapacity for magento: The phone number is a hard-coded mandatory field, after a year of discussion nothing happened with this field and last but not least, i can not understand why there are are so much changes in a DRY, high flexibility codebase are needed. Sorry, but i will disadvise my customers to use magento for a shop system.

Same here. We will discuss later this year if we should rely on Magento2 for the next projects.

We have too man issues with M2 which costs us so much money. At least wait until Nov 2018 when M1 is not supported anymore, maybe then M2 gets out of its alpha phase.

Is there any possibility to see the current roadmap for M2? I have a lot of requests for this at http://mehr-medialeitwerk.de/ .

Its a shame that you actually offer a DB-Column to turn this off but still validate the field hardcoded and that too at different places
"DRY" "SOLID"
plus your developers actually use interfaces and classes for the same instance in constructor DI
eg. _Magento\Customer\Api\AddressRepositoryInterface_ and _Magento\Customer\Model\ResourceModel\AddressRepository_

you guys really should try to make our lives easier with M2 and not worse than M1

@ilol can you pls point me to a supervisor or person we can speak as a agency. We are really close before to throw the towel on magento2. It seems like this is not gonna work for us like this at all. Spending more time in bugfixing then anything else. And also i see no change at all here also some magento people always say "they heard us" and "will implement" another system to fix bugs better. One year seems to be enough for me and my team now so we are going to make a decision here now.

Really disappointed by this as well - I kind of feel @andidhouse his problems, I chose to work with this, but bugfixing (and if you ask me this IS a bug) takes most of my time. 6 places to fix a non-required phone number is not cutting it.

5 month later. no solution. no update. really do not know if putting bugs and requests here is worth the effort any more...

I've stopped long time ago. Not worth to put any effort into Magento2.

@SchumacherFM - completly agree. We just have one project which needs to go live in some weeks and it is horrible with m2. After this project we will also stop developing m2 systems until magento changes its policy and offers a system which can be used for production without fixing hundreds of bugs. It was really the wrong decision to put one year of work in to m2.

An alternative would be: OroCommerce for B2B and Sylius for B2C

there are several design decisions in m2 that are flat out weird if not horrible, on the other hand, when was m1 fully stable? when was the feature set mature enough for most peoples needs? magento strives to be the swissarmy knife of shops so it has a wide configurable functionality. I think the main issue here is a lack of communication and that magento is developed behind closed doors (no public roadmap or ticket system).

I can send fix for $70 :1st_place_medal: :dancer:

I have created a module which removes the requirement on the telephone input:
https://github.com/zsoerenm/magento2-optionaltelephone
It can be installed via composer

@zsoerenm - Many thanks!

FYI the pull request referenced above was merged so this change will be available in 2.2.

@piotrekkaminski any information when 2.2 is planned to release?
Without an info here a planning is not possible...
Thanks!

ok no information - expected nothing else. no timeline no info.. 馃憥

@zsoerenm Thank you for sharing your module. I have used the same to make city field optional.

Was this page helpful?
0 / 5 - 0 ratings