adam2k
adam2k

Reputation: 440

Get Password Value When Creating Account during WooCommerce Checkout

I am connecting to an external CRM API where I am trying to create an account using the same username and password (that a customer creates when signing up on the checkout page) for both accounts. It is possible to get the user password before it is hashed with Wordpress?

I am accessing all the other user order info that I need from WooCommerce and passing through the API to the CRM:

$order = new WC_Order($order_id);
$order->billing_first_name;
$order->billing_last_name;
...

I only need the password un-hashed momentarily. I've looked over the WC_Order documentation here: http://docs.woothemes.com/wc-apidocs/class-WC_Order.html and didn't see a good answer.

To be clear, I am not posting the un-hashed password to either database. WP is going to hash the PW and store it as it normally does. I am trying to create another account at the same time with the same username and password via the Neon API http://help.neoncrm.com/node/12. I don't believe this is possible to do if the pw is already hashed by WP.

Upvotes: 1

Views: 3880

Answers (1)

adam2k
adam2k

Reputation: 440

I solved the problem with a custom WooCommerce plugin that hooks into

'woocommerce_order_status_completed'  

This filter needs to be triggered during the checkout phase because we are accessing the password field via $_POST during the checkout/account creation process. To trigger this filter the order status needs to be updated to completed by using this filter:

'woocommerce_payment_complete_order_status'  

You can see the full method and filter here: http://www.rcorreia.com/woocommerce/woocommerce-automatically-set-order-status-payment-received/

Inside of the filter method in your plugin or theme for

'woocommerce_order_status_completed'

the account password can be passed to the Neon api by doing something like:

$accountPassword = sanitize_text_field($_POST['account_password']);

then passing the other user data request parameters with the password like:

array( ... 'individualAccount.login.password' => $accountPassword);

Upvotes: 2

Related Questions