I can add custom fields for my Woocommerce registration form, but how would I go about rearranging them with existing fields?
My default Woocommerce registration form has fields Username, Email and Password.
So if I add custom fields Phone, First Name and Last name with this code bellow they will appear before those default fields, but how can I change their order? For example I want to put Phone after password, but keep First and Last name to be first.
function wooc_extra_register_fields() {?>
<p >
<label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label>
<input type="text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
</p>
<p >
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span >*</span></label>
<input type="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 >
<label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span >*</span></label>
<input type="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>
<div ></div>
<?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
CodePudding user response:
I've just found out, you can change custom fields placement by using these hooks:
woocommerce_register_form_start – at the beginning of the form
woocommerce_register_form – before the “Register” button
woocommerce_register_form_end - after the “Register” button
CodePudding user response:
You can rearrange checkout field by using below code put on functions.php file:
Change priority as you want
add_filter("woocommerce_checkout_fields", "custom_override_checkout_fields", 1);
function custom_override_checkout_fields($fields) {
$fields['billing']['billing_first_name']['priority'] = 1;
$fields['billing']['billing_last_name']['priority'] = 2;
$fields['billing']['billing_company']['priority'] = 3;
$fields['billing']['billing_country']['priority'] = 4;
$fields['billing']['billing_state']['priority'] = 5;
$fields['billing']['billing_address_1']['priority'] = 6;
$fields['billing']['billing_address_2']['priority'] = 7;
$fields['billing']['billing_city']['priority'] = 8;
$fields['billing']['billing_postcode']['priority'] = 9;
$fields['billing']['billing_email']['priority'] = 10;
$fields['billing']['billing_phone']['priority'] = 11;
return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'custom_override_default_locale_fields' );
function custom_override_default_locale_fields( $fields ) {
$fields['state']['priority'] = 5;
$fields['address_1']['priority'] = 6;
$fields['address_2']['priority'] = 7;
return $fields;
}