NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Easy

---- Last modified : Sep 07 2022

Estimated reading time : 0 minutes, 42 seconds - 64 words

With this tutorial, we will force a number of characters in the Woocommerce ID: order_comments.

Maximum number of Characters WooCommerce Filter

Add this filter to your functions.php file and then change the number 300 for the number of characters you want. This will force users to limit their message to the number of characters you’ll have set.

/////////////////////////////////////////////////////////////////
// Forcer max caraters div message commande /////////////////////
/////////////////////////////////////////////////////////////////

add_filter( 'woocommerce_checkout_fields', 'themespress_checkout_fields' );
function themespress_checkout_fields( $fields ) {
	$fields['order']['order_comments']['maxlength'] = 300;
	return $fields;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>