Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/c8dbbe7ccdea3463312e5b865ad92d92 to your computer and use it in GitHub Desktop.
Save webdados/c8dbbe7ccdea3463312e5b865ad92d92 to your computer and use it in GitHub Desktop.
Add custom field "client type" to WooCommerce registration
/* 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