Background

Some time ago now our client ComeFruta asked us for an improvement in their online shop that we believe may turn out to be interesting to other users, and that is why today we are sharing it in this tutorial.

Specifically, we were asked to limit the number of characters in some fields of the WooCommerce order form. They needed to limit the number of characters of the Street address fields of the billing form and of the shipping form, and of the Order notes field. The limit had to be set to 50 characters in the first two fields and to 70 characters in the third one.

The reason why they needed to limit the maximum number of characters allowed in these three fields of the WooCommerce order form was that in the automated CSV they send to whichever transport company they use, no more characters were accepted in these fields and they caused them serious problems in the automatic imports.

Solution

After our client’s request we got down to work and created a small PHP function in the functions.php file of the child theme.

This small PHP function takes care of adding a small piece of JavaScript code exclusively to the WooCommerce checkout page that adds the maxlength attribute in the requested fields with the maximum number of characters allowed in each of them:

Copy to clipboard

Obviously, thanks to small modifications to this PHP function and the JavaScript code it contains, you can make other fields of the order form have character limits too, add additional custom attributes to them or modify any existing attribute at will. The options the JavaScript code offers us on the order form, its billing and shipping forms and the different fields that make them up are almost infinite.

We hope you like this little tutorial and find it useful, that you can use it in your online shops and that it solves more than one problem for you in the future.

We look forward to your comments and contributions.

Related posts

Comments

Suscríbete
Notificar de
0 Comments
Más antiguos
Más recientes Más votados

In this post

Products and services

Latest posts

Latest comments

Subscribe!

Lista de correos de APG

DATA PROTECTION: In accordance with data protection regulations, we provide you with the following processing information: (+)

  • Responsible: Art Project Group.
  • Treatment purposes: to respond to queries or any type of request made by the user through any of the forms of contact that are made available on the website. Sending communications about products or services (with your consent).
  • Your rights: access, rectification, portability, deletion, limitation and opposition. More information about the treatment in the Privacy Policy.

What we post on !

Se ha publicado #WooCommerce 11.2.2: actualización de seguridad que refuerza las API REST y Store, mejora la validación de CSV y corrige problemas en pagos y pedidos. Incluye cambios en la base de datos.

¡Actualiza cuanto antes!

November 5, 2026