A while ago I wrote a post about how to remove the password strength meter from the Checkout page. Since I strongly encourage you to not remove it though, like mentioned in that article as well, just changing the meter labels to something easier to understand can help instead!
By changing the meter labels you can explain what could be wrong with the password used, even if that would be hard since the script uses a 3rd-party tool to check the strength of a password which does not only check its length, presence of specific characters, numbers or signs.
You can read more about how it works on WP Tavern.
Probably you already understood that the password strength meter script is not from WooCommerce, so we have to change the meter labels in WordPress directly.
There’s a way to do it, you need to re-localize the script in your theme.
Since the theme is loaded after the core of WordPress, the new localization will load after the one in the core, and this last one will be used instead.
Open your functions.php
file located in wp-content/themes/your-child-theme-name/
and add this code at the end of it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_enqueue_scripts', 'my_strength_meter_localize_script' ); | |
function my_strength_meter_localize_script() { | |
wp_localize_script( 'password-strength-meter', 'pwsL10n', array( | |
'empty' => __( 'But… it\'s empty!', 'theme-domain' ), | |
'short' => __( 'Too short!', 'theme-domain' ), | |
'bad' => __( 'Not even close!', 'theme-domain' ), | |
'good' => __( 'You are getting closer…', 'theme-domain' ), | |
'strong' => __( 'Now, that\'s a password!', 'theme-domain' ), | |
'mismatch' => __( 'They are completely different, come on!', 'theme-domain' ) | |
) ); | |
} |
Now these new meter labels will be used instead of the core meter labels. They will be used everywhere the password strength meter is used, so in the edit user screen in the Dashboard, in the My Account page if the registration form is enabled and on the checkout page as well.
Update 23rd Feb. 2016: You can change also the default messages returned by WooCommerce. To do so, use this code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_get_script_data', 'my_strength_meter_custom_strings', 10, 2 ); | |
function my_strength_meter_custom_strings( $data, $handle ) { | |
if ( 'wc-password-strength-meter' === $handle ) { | |
$data_new = array( | |
'i18n_password_error' => esc_attr__( 'Come on, enter a stronger password.', 'theme-domain' ), | |
'i18n_password_hint' => esc_attr__( 'The password should be at least seven characters long.', 'theme-domain' ) | |
); | |
$data = array_merge( $data, $data_new ); | |
} | |
return $data; | |
} |
Update 12th Feb. 2018: The code above only works from WooCommerce 3.3+. If you are running an older version of WooCommerce you should use this script instead.
Leave a Reply