I hate posting answers to my own questions but it seems that as the one who has need of it most pressingly I have gone the distance here.. as is too often the case..
So after trying numerous techniques including:
1) making attributes as not required in the eav attributes
table in the database;
2) programatically adding these required fields to the database upon billing update (with event)
The best that I have come up with that works (very well) is to create hidden fields for any fields that are required but not relevant - in my case city
, region
and postcode
- and include them inside the form. The easiest way to do this I believe is to create a function for this in a custom module file like so (changing $inputFields_arr
to correspond to the required fields you wish to ignore):
public function getRequiredNotRequestedInputs($prefix) { // fill in input values required but not wanted
$value = 'NOT REQUESTED';
$inputFields_arr = array('city', 'region', 'postcode'); // required fields that we don't need/request
foreach($inputFields_arr as $inputField) {
$return_arr[] = '<input type="hidden" name="'.$prefix.'['.$inputField.']" id="'.$prefix.':'.$inputField.'" value="'.$value.'" />';
}
return implode('',$return_arr);
}
Then call this like this:
<?php echo $moduleFile->getRequiredNotRequestedInputs('billing'); // set city, postcode, etc ?>
..from whatever point you want (where $moduleFile
is the file you stored the above function in). In my case I've called this in:
app/design/frontend/default/YOUR-TEMPLATE/template/YOUR-CUSTOM-LAYOUT/checkout/billing.phtml
I know that there are those out there that will want to do this the quick and nasty way (and that is your perogative) by putting the hidden fields directly into a local front-end file (and overriding the core) but after learning to use custom modules with all that you can it will not only help you to update (a well-heard sermon) it will keep things tidy and for me that is more than half the battle. Hope this is helpful to others.
Best Answer
To change phone number into optional follow the below configuration setup
Go to
Admin Login -> Stores -> (Settings) Configuration -> Customers(Tab) -> Customer Configuration -> Name and Address Options.
In their change Show Telephone is Required into Optional.
Now the checkout page is not asking the Phone number is required.