Skip to content

Commit 63e8c7b

Browse files
committed
Implement account creation and linking
1 parent 783c773 commit 63e8c7b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

includes/class-wc-gateway-amazon-payments-advanced.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,27 @@ public function handle_account_registration( $customer_id ) {
299299
delete_user_meta( $user_id, 'wc_apa_ownership_verification_code' );
300300
}
301301

302+
if ( ! $customer_id ) {
303+
$username = ! empty( $data['account_username'] ) ? $data['account_username'] : '';
304+
$password = ! empty( $data['account_password'] ) ? $data['account_password'] : '';
305+
306+
$customer_id = wc_create_new_customer(
307+
$data['billing_email'],
308+
$username,
309+
$password,
310+
array(
311+
'first_name' => ! empty( $data['billing_first_name'] ) ? $data['billing_first_name'] : '',
312+
'last_name' => ! empty( $data['billing_last_name'] ) ? $data['billing_last_name'] : '',
313+
)
314+
);
315+
316+
if ( is_wp_error( $customer_id ) ) {
317+
throw new Exception( $customer_id->get_error_message() );
318+
}
319+
320+
$this->set_customer_id_for_buyer( $buyer_id, $customer_id );
321+
}
322+
302323
wc_set_customer_auth_cookie( $customer_id );
303324

304325
// As we are now logged in, checkout will need to refresh to show logged in data.

0 commit comments

Comments
 (0)