Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created February 2, 2022 11:52
Show Gist options
  • Save kimcoleman/ca26f33c0f482e01abcae00219a8d2f5 to your computer and use it in GitHub Desktop.
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.
<?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