Skip to content

Instantly share code, notes, and snippets.

@hiendnguyen
Last active March 7, 2017 06:14
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 hiendnguyen/e786ca609d46d491719067fe1550f6c2 to your computer and use it in GitHub Desktop.
Save hiendnguyen/e786ca609d46d491719067fe1550f6c2 to your computer and use it in GitHub Desktop.
WooCommerce Registration Custom Fields Frontend
function wooc_extra_register_fields() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
<p class="form-row form-row-last">
<label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
</p>
<p class="form-row form-row-wide">
<label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone']); ?>" />
</p>
<p class="form-row form-row-wide">
<label for="billing_company"><?php _e( 'Company', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_company" id="billing_company" value="<?php if ( ! empty( $_POST['billing_company'] ) ) esc_attr_e( $_POST['billing_company']); ?>" />
</p>
<p class="form-row form-row-wide">
<label for="user_role">Register as</label>
<select id="user_role" name="user_role" style="height: 34px;">
<option value="subscriber">Subscriber</option>
<option value="contributor">Contributor</option>
<option value="employer">Employer</option>
<option value="customer">Customer</option>
<select>
</p>
<div class="clear"></div>
<?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
function wooc_subscribe_to_newsletter(){
?>
<p class="form-row form-row-wide" id="subscribe_to_newsletter_field"><label class="checkbox ">
<input type="checkbox" class="input-checkbox " name="subscribe_to_newsletter" id="subscribe_to_newsletter" value="1" checked="checked"> Subscribe to our newsletter?</label></p>
<?php
}
add_action( 'woocommerce_register_form', 'wooc_subscribe_to_newsletter' );
/** DISABLE THE FIRST NAME AND LAST NAMES CREATED BY PLUGIN WOOCOMMERCE SIMPLE REGISTRATION, BECAUSE THEY APPEAR IN ENGLISH ONLY, NOT BEING TRANSLATED. */
add_filter( 'woocommerce_simple_registration_name_fields', '__return_false' );
/** Add agree to terms and conditions for WooCommerce registration. */
function wooc_agree_terms_conditions(){
?>
<p>By clicking on "REGISTER", I have read and accepted <b><a href="/privacy/" target="_blank">Privacy Policy</a> and <b><a href="/terms/" target="_blank">Terms of Use</a>.</p>
<?php
}
add_action( 'woocommerce_register_form_end', 'wooc_agree_terms_conditions');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment