WordPress.org

Support

Support » Plugins and Hacks » Password confirmation in woocommerce 2.1.x release

Password confirmation in woocommerce 2.1.x release

  • K B
    Member

    @kiritb

    I can’t seem to find any setting that forces a new user to enter their password twice while creating a new account. I’m quite certain I saw a password confirmation option as a default in woocommerce 2.0 but I don’t see it in 2.1.

    What am I missing here? How can I get password confirmation back?

    https://wordpress.org/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • That’s not a WooCommerce specific setting. It may be a general WordPress setting or a plugin.

    Peter Brock
    Member

    @peter-brock

    In previous versions, this code added to functions.php created a password confirmation field.

    add_filter( 'woocommerce_checkout_fields', 'custom_checkout_fields' );
    
    function custom_checkout_fields( $fields ) {
    
    $fields['account']['account_password']['label'] = 'Choose a password';
    $fields['account']['account_password']['class'] = 'form-row-first';
    $fields['account']['account_password-2']['class'] = 'form-row-last';
    $fields['account']['account_password-2']['placeholder'] = 'Confirm password';
    
    return $fields;
    }

    Alas, it no longer works. In 2.1 it messes with checkout in a fatal way and I had to comment it out.

    I don’t know what’s wrong or why there is a conflict.

    Suggestions welcome.

    after adding second password field with this code;

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
    	$fields['account']['account_password-2'] = array(
            'label'     	=> __('Confirm Password', 'woocommerce'),
    		'placeholder'   => _x('Confirm Password', 'placeholder', 'woocommerce'),
    		'required'  	=> true,
    		'class'     	=> array('form-row, form-row-wide'),
    		'clear'     	=> true,
    		'type'     	=> 'password',
         );
    
         return $fields;
    }

    then add this code to your functions.php

    // Check the password and confirm password fields match before allow checkout to proceed.
    add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 );
    function wc_check_confirm_password_matches_checkout( $posted ) {
    	$checkout = WC()->checkout;
    	if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) {
    		if ( strcmp( $posted['account_password'], $posted['account_password-2'] ) !== 0 ) {
    			wc_add_notice( __( 'Passwords not match.', 'woocommerce' ), 'error' );
    		}
    	}
    }
    Peter Brock
    Member

    @peter-brock

    Thank you, ewroman. Your code solves my problem. I have my password confirmation field back.

    Soveet
    Member

    @soveet_g

    Thanks ewroman. Works perfect.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Password confirmation in woocommerce 2.1.x release’ is closed to new replies.