Code-Snippets-Functions/Execute a function on a child site/WooCommerce/remove-blank-space-when-creating-a-user.txt

17 lines
755 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

add_filter( woocommerce_new_customer_data, custom_new_customer_data, 10, 1 );
function custom_new_customer_data( $new_customer_data ){
// get the first and last billing names
if(isset($_POST[billing_first_name])) $first_name = $_POST[billing_first_name];
if(isset($_POST[billing_last_name])) $last_name = $_POST[billing_last_name];
// the customer billing complete name
if( ! empty($first_name) || ! empty($last_name) )
$complete_name = $first_name . . $last_name;
// Replacing user_login in the user data array, before data is inserted
if( ! empty($complete_name) )
$new_customer_data[user_login] = sanitize_user( str_replace( , -, $complete_name ) );
return $new_customer_data;
}