$_POST["billing_name"]
add_action( 'woocommerce_thankyou', 'create_customer' );
function create_customer() {
$customers = get_users( array( 'role' => 'customer' ) );
foreach( $customers as $customer ) :
$my_customer = get_user_meta( $customer->ID, 'billing_company', true );
if($my_customer!=$_POST["billing_company"]) {
$userdata = array(
'user_pass' => '123',
'user_login' => $_POST["billing_name"],
'user_email' => $_POST["billing_email"],
'user_company' => $_POST["billing_company"],
'role' => 'customer',
);
wp_insert_user( $userdata );
}
endforeach;
}
add_action( 'woocommerce_thankyou', 'create_user_callback' );
function create_user_callback($order_id){
$order = wc_get_order( $order_id );
$order_detail['customer_first_name'] = get_post_meta( $order_id, '_billing_first_name', true );
$order_detail['customer_phone'] = get_post_meta( $order_id, '_billing_phone', true );
$order_detail['customer_email'] = get_post_meta( $order_id, '_billing_email', true );
$order_detail['customer_address'] = get_post_meta( $order_id, '_billing_address_2', true );
$customers = get_users( array( 'role' => 'customer' ) );
foreach( $customers as $customer ) :
$customers_email = get_user_meta( $customer->ID, 'billing_phone', true );
if($customers_phone!=$order_detail['customer_phone'] && $customer->user_email!=$order_detail['billing_email']) {
$userdata = array(
'user_pass' => '123',
'user_login' => $order_detail['customer_email'],
'first_name' => $order_detail['customer_first_name'],
'user_email' => $order_detail['customer_email'],
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
if ( !is_wp_error( $userid ) ) {
add_user_meta( $userid, 'billing_phone', $order_detail['customer_phone'] );
add_user_meta( $userid, 'billing_address_2', $order_detail['customer_address'] );
}
}
endforeach;
}