Change label in woocommerce login/register in WordPress
Hello mates, In this article I am going to show you how to change the default labels in woocommerce login/register form in WordPress. Generally, Woo-commerce let the developers to change the texts and functions of the forms by using actions and filters. So in order to create actions and filters you might need to know basic PHP coding. But if you don’t familiar with it don’t worry. Ill show the easiest way to alter the text of those forms. So lets get started
In order to modify labels in woocommerce forms you have to modify some PHP files under your theme folder. So to do this you don’t need server access. If you are an admin or you have access to change theme files in the WordPress project you can follow this and able to change those labels easily
Step 1
Go to Appearance->Theme Editor
Step 2
Select functions.php file
Below Image is for reference
Step 3
After clicking on functions.php file you might see php coding in the view. So here I am going to show how to change Username label in woo-commerce login form. Now place the below codes in this file.
add_filter( 'gettext', 'change_registration_usename_label', 10, 3 );
function change_registration_usename_label( $translated, $text, $domain ) {
if( is_account_page() && ! is_wc_endpoint_url() ) {
if( $text === 'Username' ) {
$translated = __( 'Account number', $domain );
} elseif( $text === 'Username or email address' ) {
$translated = __( 'Account number or email address', $domain );
}
}
return $translated;
}
If your form contains the label name as ‘Username’, It will convert to ‘Account number’. Or if your form contains ‘Username or email address’, then it will convert to ‘Account number or email address’ according to above code.
Extra Tip – Another example to change ‘Account number’ label
add_filter( 'gettext', 'change_registration_usename_label', 10, 3 );
function change_registration_usename_label( $translated, $text, $domain ) {
if( is_account_page() && ! is_wc_endpoint_url() ) {
if( $text === 'Account number' ) {
$translated = __( 'Full Name', $domain );
}
}
return $translated;
}
According to the above code, If your form contains the label name as ‘Account number’, It will convert to ‘Full Name.
That’s it about change labels in woocommerce wordpress development!! If you have any questions please comment below. If you want to read more articles, click on below link.