skip to Main Content

Is there any way to retrieve the clean unhashed password value in the WooCommerce checkout page with any hook?

What I need to do: I need to create a Firebase Auth user when a new WordPress user is creating. If this is not possible, what would be the best practice to achieve this?

What I tried

First I tried to create a new custom field on checkout and retrieve it with:

function wh_CustomReadOrder($order_id)
{
    $order = wc_get_order($order_id);
    WC()->session = new WC_Session_Handler;

    /*
    * Next lets create a customer so we can access checkout fields
    * If you will check a constructor for WC_Customer class you will see
    * that if you will not provide user to create customer it will use some
    * default one. Magic.
    */
    WC()->customer = new WC_Customer;

    /*
    * Done. You can browse all chceckout fields (including custom ones)
    */
    ?>
  <script type="text/javascript">
      var order = <?php echo $order ?>;
      var checkout_fields = <?php echo json_encode(WC()->checkout->checkout_fields) ?>

      var email = order;
      console.log(checkout_fields);
  </script>
    <?php
}

add_action('woocommerce_thankyou', 'wh_CustomReadOrder');

I get an array with all fields, but my custom field is not showing. But even if so, the WordPress password will still be different. The best way would be to simply get the WordPress password and then create the user in Firebase.

Do you have any idea?

2

Answers


  1. One approach I would consider is to build a custom webform for creating the customer’s account. That way you can manipulate the data however you want.

    For example, when the user submits the form, take the data, register the new user in WC/WP, send the data to firebase, then redirect.

    The downside is that you’ll have to manage the process a 100% and deal with any possible errors.

    Another way:

    Use the default WC or WP account creation form, but on submit -> prevent Default with Javascript, take the data (yes you can access the password before it’s hashed), send it to Firebase, THEN, submit the form and let WC/WP save it in the database in a normal fashion.

    I did it like this when I needed to send that data to an Email Management software. The user enters the values, hits submit: my code blocks the submit event, sends the data where I want it to, then submits the form.

    Hope it helps!

    Login or Signup to reply.
  2. As you will see in the wc-user-functions.php file, the function wc_create_new_customer is used when creating a new account.


    For checking the checkout page you can use Conditional Tags

    • is_checkout() Returns true on the checkout page.

    So to intercept the unhashed password you could use the woocommerce_created_customer hook. The $unhashed_password variable will contain the unhashed password.

    function action_woocommerce_created_customer ( $customer_id, $new_customer_data, $password_generated ) {    
        // Returns true on the checkout page.
        if ( is_checkout() ) {
            $unhashed_password = $new_customer_data['user_pass'];
        }
    }
    add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search