My Account

WooCommerce Force Numeric Usernames On Registration

WooCommerce registration form showing an error is the username does not contain numbers only


There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This code snippet shows you how to make the registration form on the My Account page show an error is a user defined username is not numeric. This guide is particularly useful if you would like usernames to be an ID which already exists in the business.

 * Snippet Name:	WooCommerce Force Numeric Usernames On Registration
 * Snippet Author:

add_action( 'woocommerce_register_post', 'ecommercehints_force_numeric_username', 10, 3 );
function ecommercehints_force_numeric_username( $username, $email, $errors ) {
	if ( !is_numeric($username) ) {
		$errors->add( 'numeric_username_error', 'Your username must be numeric only' );

Snippet Benefits

  • Force WooCommerce usernames to only contain numbers otherwise show an error

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.