Created
November 8, 2016 14:14
-
-
Save claudiosanches/ae9a8b496c431bec661b69ef73f1a087 to your computer and use it in GitHub Desktop.
WooCommerce - Saving new "My account" registration fields
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 | |
/** | |
* Save the extra register fields. | |
* | |
* @param int $customer_id Current customer ID. | |
*/ | |
function wooc_save_extra_register_fields( $customer_id ) { | |
if ( isset( $_POST['billing_first_name'] ) ) { | |
// WordPress default first name field. | |
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) ); | |
// WooCommerce billing first name. | |
update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) ); | |
} | |
if ( isset( $_POST['billing_last_name'] ) ) { | |
// WordPress default last name field. | |
update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); | |
// WooCommerce billing last name. | |
update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); | |
} | |
if ( isset( $_POST['billing_phone'] ) ) { | |
// WooCommerce billing phone | |
update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) ); | |
} | |
} | |
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment