Created
November 21, 2017 08:13
-
-
Save webdados/c8dbbe7ccdea3463312e5b865ad92d92 to your computer and use it in GitHub Desktop.
Add custom field "client type" to WooCommerce registration
This file contains 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
/* Add client type field to registration */ | |
add_action( 'woocommerce_register_form_start', 'woocommerce_register_form_start_client_type' ); | |
function woocommerce_register_form_start_client_type() { | |
?> | |
<p class="form-row form-row-wide"> | |
<label for="reg_client_type"><?php _e( 'Client type', 'textdomain' ); ?></label> | |
<select class="" name="client_type" id="client_type"> | |
<option value="person"<?php if ( isset($_POST['client_type']) && $_POST['client_type']=='person' ) echo ' selected="selected"'; ?>><?php _e( 'Person', 'textdomain' ); ?></option> | |
<option value="company"<?php if ( isset($_POST['client_type']) && $_POST['client_type']=='company' ) echo ' selected="selected"'; ?>><?php _e( 'Company', 'textdomain' ); ?></option> | |
</select> | |
</p> | |
<?php | |
} | |
/* Update user */ | |
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_client_type', 10, 3 ); | |
function woocommerce_created_customer_client_type( $customer_id ) { | |
if ( isset( $_POST['client_type'] ) ) { | |
update_user_meta( $customer_id, 'client_type', sanitize_text_field( $_POST['client_type'] ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment