Home > Software engineering >  WooCommerce doesn't send the password to the customer registered on the "My account"
WooCommerce doesn't send the password to the customer registered on the "My account"

Time:12-22

Although the "When creating an account, automatically generate an account password" option is checked, when the user registers on the "My account" page the WooCommerce doesn't send the password to the user, only a password setting link "Click here to set your new password.". On the other hand, when the registration is made from the checkout page, the password is sent. How can it be sent after on the "My Account" page registration as well?

Today I searched all day for a solution to this problem, one that does not involve editing templates, but I did not find one.

enter image description here

When the customer registers via "My account" the notification looks like in the picture.

CodePudding user response:

Even if you have checked the "When creating an account, automatically generate an account password" option, due to an adjustment have been made since November 19th in WooCommerce 6.0.0, now the new customers will receive a notification email without the automatically generated password, as was up to 5.9.0, although it exists, but with a link inviting to set a new password (thanks @7uc1f3r for this info).

Initially, I wanted to revert the changes made in WooCommerce 6.0.0, but after some time of analysis, I decided that the new changes are good in terms of account security. But now, immediately after registration and completion of the order, the customer is logged in but does not have a password available, because it was not sent to him, even if it was created. And because not everyone reads their emails regularly, I have added an additional notification for new customers, for example on the "Order Received" page, which warns them supplementary about the need to set a password, so they don't feel lost when later discovers that they do not have access to their account due to the lack of a password.

/** Add a user meta when a new customer account is created **/
add_action( 'woocommerce_created_customer', function( $customer_id ) {
    add_user_meta( $customer_id, '_is_new_user', 'yes' );
} );

/** Add a notice to the "Order received" page if is a new registered customer **/
add_action( 'woocommerce_before_thankyou', function() {
    $current_user = wp_get_current_user();

    if( $current_user->ID > 0 && 'yes' === get_user_meta( $current_user->ID, '_is_new_user', true ) ) {
        wc_print_notice( $current_user->first_name . ', thank you for creating an account on <em>' . get_option('blogname'). '</em>. We sent you to <em>' . $current_user->user_email . '</em> an email with useful information about your account. Attention, if you can't find it, check in your spam folder. To better secure your account, we recommend that you set a new password and save it in a safe place.', 'success' );

        //delete the user meta added when the new customer account was created
        delete_user_meta( $current_user->ID, '_is_new_user' );
    }
} );
  • Related