---
title: "Limiting the number of characters"
description: "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"
url: https://artprojectgroup.com/limiting-the-number-of-characters
date: 2017-12-27
modified: 2023-02-12
author: "Art Project Group"
image: https://artprojectgroup.com/wp-content/uploads/2023/04/woocommerce-blog.webp
categories: ["Tutorials"]
tags: ["functions.php", "JavaScript", "PHP", "WooCommerce"]
type: post
lang: en-US
---

# Limiting the number of characters

## Background

Some time ago now our client [ComeFruta](https://comefruta.es) 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 clipboardSyntax Highlighter/*
Limiting the characters in the billing form.
*/
function apg_maxlength_checkout() {
if ( !is_checkout() ) {
return;
}
?>
