• Resolved Husain Ahmed

    (@husainahmedqureshi)


    Hello,
    I have update woo-commerce in latest version 3.0.1 Because of which some of my functions have been closed like confirm password fields on check out page. my function is
    add_action( ‘woocommerce_checkout_init’, ‘wc_add_confirm_password_checkout’, 10, 1 );
    function wc_add_confirm_password_checkout( $checkout ) {
    if ( get_option( ‘woocommerce_registration_generate_password’ ) == ‘no’ ) {
    $checkout->checkout_fields[‘account’][‘account_password2’] = array(
    ‘type’ => ‘password’,
    ‘label’ => __( ‘Verify password’, ‘woocommerce’ ),
    ‘required’ => true,
    ‘placeholder’ => _x( ‘Password’, ‘placeholder’, ‘woocommerce’ )
    );
    }
    }

    How can i correct my function.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Where is the code to actually handle the new field? That may need updating.

    Mine stopped working after updating woocommerce too.

    // Add a second password field to the checkout page.
    add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 );
    function wc_add_confirm_password_checkout( $checkout ) {
    if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
    $checkout->checkout_fields['account']['account_password2'] = array(
    'type' => 'password',
    'label' => __( 'Confirm password', 'woocommerce' ),
    'required' => true,
    'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' )
    );
    }
    }
    // 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_password2'] ) !== 0 ) {
    wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' );
    }
    }
    }

    There is only one password field, so when checking out it says passwords do not match because second password field isn’t there. Any ideas? This was working perfectly before updating woocommerce.

    Hi there

    I am also using the same code but it stops working after update. ?I was firstly thinking it was issue with some plugins or something else but now i think its only issue with woocommerce update.

    Can anybody please help me?

    Thanks

    • This reply was modified 7 years, 7 months ago by puja_thewebco.
    Thread Starter Husain Ahmed

    (@husainahmedqureshi)

    hello guys,

    I have found solution for conform password field on checkout page in
    Woocommerce 3.0.3
    By using below code we have add a conform password field in checkout page.
    copy this code and past on function.php file that is on your themes folder.

    /**
    * Add a confirm password field to the checkout registration form.
    */
    function o_woocommerce_confirm_password_checkout( $checkout ) {
    if ( get_option( ‘woocommerce_registration_generate_password’ ) == ‘no’ ) {

    $fields = $checkout->get_checkout_fields();

    $fields[‘account’][‘account_confirm_password’] = array(
    ‘type’ => ‘password’,
    ‘label’ => __( ‘Confirm password’, ‘woocommerce’ ),
    ‘required’ => true,
    ‘placeholder’ => _x( ‘Confirm Password’, ‘placeholder’, ‘woocommerce’ )
    );

    $checkout->__set( ‘checkout_fields’, $fields );
    }
    }
    add_action( ‘woocommerce_checkout_init’, ‘o_woocommerce_confirm_password_checkout’, 10, 1 );

    /**
    * Validate that the two password fields match.
    */
    function o_woocommerce_confirm_password_validation( $posted ) {
    $checkout = WC()->checkout;
    if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted[‘createaccount’] ) ) ) {
    if ( strcmp( $posted[‘account_password’], $posted[‘account_confirm_password’] ) !== 0 ) {
    wc_add_notice( __( ‘Passwords do not match.’, ‘woocommerce’ ), ‘error’ );
    }
    }
    }
    add_action( ‘woocommerce_after_checkout_validation’, ‘o_woocommerce_confirm_password_validation’, 10, 2 );

    Hello @husainahmedqureshi
    It does added a new field for confirm password but the issue “Passwords do not match.” is still there.

    Thread Starter Husain Ahmed

    (@husainahmedqureshi)

    /**
    * Add a confirm password field to the checkout registration form.
    */
    function o_woocommerce_confirm_password_checkout( $checkout ) {
    if ( get_option( ‘woocommerce_registration_generate_password’ ) == ‘no’ ) {
    $fields = $checkout->get_checkout_fields();
    $fields[‘account’][‘account_password2’] = array(
    ‘type’ => ‘password’,
    ‘label’ => __( ‘Verify password’, ‘woocommerce’ ),
    ‘required’ => true,
    ‘placeholder’ => _x( ‘Verify password’, ‘placeholder’, ‘woocommerce’ )
    );
    $checkout->__set( ‘checkout_fields’, $fields );
    }
    }
    add_action( ‘woocommerce_checkout_init’, ‘o_woocommerce_confirm_password_checkout’, 10, 1 );

    /**
    * Validate that the two password fields match.
    */
    function o_woocommerce_confirm_password_validation( $posted ) {
    $checkout = WC()->checkout;
    if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted[‘createaccount’] ) ) ) {
    if ( strcmp( $posted[‘account_password’], $posted[‘account_password2’] ) !== 0 ) {
    wc_add_notice( __( ‘Passwords do not match.’, ‘woocommerce’ ), ‘error’ );
    }
    }
    }
    add_action( ‘woocommerce_after_checkout_validation’, ‘o_woocommerce_confirm_password_validation’, 10, 2 );

    Password didn’t match because of fields name is mismatch. Please match your code from below line

    $fields[‘account’][‘account_password2’] = array(

    if ( strcmp( $posted[‘account_password’], $posted[‘account_password2’] )

    • This reply was modified 7 years, 7 months ago by Husain Ahmed.

    I attempted to use this code but when inserted into my Functions file it generated the following errors

    T_String error for ‘label’ => __( ‘Verify password’, ‘woocommerce’ ),

    T_String error for ‘placeholder’ => _x( ‘Verify password’, ‘placeholder’, ‘woocommerce’ )

    T_DO error for wc_add_notice( __( ‘Passwords do not match.’, ‘woocommerce’ ), ‘error’ );

    Any insight on this? Thank you in advance.

    @touchnova

    Most probably the single quotes are angled-quotes.
    They need to be straight-quotes. Read the link below.
    https://stackoverflow.com/questions/10343946/php-angled-single-quote-vs-stright-single-quote

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Confirm Password on checkout page not working in woocommerce 3.0.0’ is closed to new replies.