WordPress.org

Forums

WooCommerce - excelling eCommerce
Password confirmation in woocommerce 2.1.x release (6 posts)

  1. K B
    Member
    Posted 1 year ago #

    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/

  2. Daniel Espinoza
    Member
    Posted 1 year ago #

    That's not a WooCommerce specific setting. It may be a general WordPress setting or a plugin.

  3. Peter Brock
    Member
    Posted 1 year ago #

    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.

  4. ewroman
    Member
    Posted 11 months ago #

    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' );
    		}
    	}
    }
  5. Peter Brock
    Member
    Posted 11 months ago #

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

  6. Soveet
    Member
    Posted 6 months ago #

    Thanks ewroman. Works perfect.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic