add_action( 'woocommerce_thankyou', 'create_user_callback' );
function create_user_callback($order_id){
$order = new WC_Order($order_id);
$order_email = $order->billing_email;
$email = email_exists( $order_email );
$user = username_exists( $order_email );
$custom = reset(
get_users(
array(
'role' => 'customer',
'meta_key' => 'billing_phone',
'meta_value' => $order->billing_phone,
'number' => 1
)
)
);
if(!$custom && $user == false && $email == false) {
$random_password = wp_generate_password();
$userdata = array(
'user_pass' => $random_password,
'user_login' => $order_email,
'first_name' => $order->billing_first_name,
'user_email' => $order_email,
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
if ( !is_wp_error( $userid ) ) {
update_user_meta( $userid, 'billing_phone', $order->billing_phone );
update_user_meta( $userid, 'billing_company', '');
update_user_meta( $userid, 'billing_full_address', $order->billing_full_address );
update_post_meta($order_id, '_customer_user', $userid);
}
wc_update_new_customer_past_orders( $userid );
}
else {
update_post_meta($order_id, '_customer_user', $custom->ID);
wc_update_new_customer_past_orders( $custom->ID );
}
}
$userdata = apply_filters( 'woocommerce_new_customer_data', array(
'user_pass' => $random_password,
'user_login' => $order_email,
'first_name' => $order->billing_first_name,
'user_email' => $order_email,
'role' => 'customer',
) );
get_user_by( 'email', $email )
для него не работает точно, проверял.wc_update_new_customer_past_orders( $userid );
"Символ" не определен в IE после использования babel
Если с вашей помощью обнаружим ошибку - обязательно зачту ваш ответ правильным