After the request from one of our clients, we had to give some thought to the code we put to you at the time in the post How do you add a NIF or CIF field to WooCommerce 2.1?, in order to get the customer’s telephone to be displayed, as well as the NIF/CIF in all the WooCommerce 2.1 address fields, and for it also to be compulsory. The reason? He needed it so that the transport company could get in touch with the customer.
Well then, so that you can see that it is really quite simple, first we are going to put the complete PHP code that needs to be added to the functions.php file of your child theme, and afterwards we will analyse the lines we have modified from the code published in the post How do you add a NIF or CIF field to WooCommerce 2.1?:
In it we have made the following modifications:
- The campos_de_direccion function, where we have told it that the telephone field is compulsory.
- The anade_campo_nif_direccion_facturacion function, where we have added the telephone field to the billing address.
- The anade_campo_nif_direccion_envio function, where we have added the telephone field to the shipping address.
- The formato_direccion_de_facturacion function, where we have added the telephone field to the replacement fields in the local address format.
- The formato_direccion_localizacion function, where we have added the telephone field to the local, Spanish, address format.
- The anade_campo_nif_usuario_direccion_facturacion function, where we have added the telephone field to the address form.
- The anade_campo_nif_usuario_direccion_envio function, where we have added the telephone field to the shipping form.
- The anade_campo_nif_editar_direccion function, where we have added the telephone field to the address forms of the My account page.
- The anade_campo_nif_editar_direccion_pedido function, where we have added the telephone field to the address forms of Orders in the WooCommerce administration panel.
- The carga_hoja_de_estilo_editar_direccion_pedido function, where we edit the CSS code of the telephone field of the previous forms.
With these modifications we will have covered 100% of the needs that WooCommerce poses to us when it comes to making a field compulsory, in this case the telephone, and to displaying it in the order and on the invoice next to another field that is not “native”, such as the NIF/CIF field.
We hope that, as always, you like this post and find it useful, and we look forward to your comments.
Related posts
Comments





