Created
February 2, 2022 11:52
-
-
Save kimcoleman/ca26f33c0f482e01abcae00219a8d2f5 to your computer and use it in GitHub Desktop.
If the POST contains the first_name and last_name fields, add to the customer created through WooCommerce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If the POST contains the first_name and last_name fields, add to the customer created through WooCommerce. | |
*/ | |
function my_woocommerce_new_customer_data( $new_customer_data ) { | |
if ( empty( $new_customer_data['first_name'] ) && isset( $_POST['first_name'] ) ) { | |
$new_customer_data['first_name'] = sanitize_text_field( $_POST['first_name'] ); | |
} | |
if ( empty( $new_customer_data['last_name'] ) && isset( $_POST['last_name'] ) ) { | |
$new_customer_data['last_name'] = sanitize_text_field( $_POST['last_name'] ); | |
} | |
return $new_customer_data; | |
} | |
add_filter( 'woocommerce_new_customer_data', 'my_woocommerce_new_customer_data' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment