Reordering checkout fields in WooCommerce 3
<p>I'm trying to re-order 2 custom checkout fields added with the help of <code>woocommerce_checkout_init</code> filter, just that when I apply <code>woocommerce_checkout_fields</code> filter to re-order fields, it doesn't recognize them and they are <code>null</code>.<br>
I think it's because the filter <code>woocommerce_checkout_init</code> goes after <code>woocommerce_checkout_fields</code>. </p>

<p>How Can I solve this?</p>

<p>Here is my code:</p>

<pre><code>add_action( 'woocommerce_checkout_init', 'wc_add_confirm_email_checkout', 10, 2 );
function wc_add_confirm_email_checkout( $checkout ) {
    $checkout-&gt;checkout_fields['billing']['billing_email2'] = array(
        'type'              =&gt; 'text',
        'label'             =&gt; __( 'Confirm Email Address', 'woocommerce' ),
        'required'          =&gt; true,
        'placeholder'       =&gt; _x( 'Confirm Email Address', 'placeholder', 'woocommerce' )
    );
}
add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 2 );
function wc_add_confirm_password_checkout( $checkout ) {
    //var_dump($checkout-&gt;checkout_fields);
    if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
        $checkout-&gt;checkout_fields['account']['account_password2'] = array(
            'type'              =&gt; 'password',
            'label'             =&gt; __( 'Confirm password', 'woocommerce' ),
            'required'          =&gt; true,
            'placeholder'       =&gt; _x( 'Confirm Password', 'placeholder', 'woocommerce' )
        );
    }
}

add_filter('woocommerce_checkout_fields','reorder_woo_fields');
function reorder_woo_fields($fields) {
    $fields2['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
    $fields2['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
    $fields2['billing']['billingooglg_email'] = $fields['billing']['billing_email'];
    $fields2['billing']['billing_email2'] = $fields['billing']['billing_email2'];
    $fields2['billing']['account_password'] = $fields['account']['account_password'];
    $fields2['billing']['account_password2'] = $fields['account']['account_password2'];
    $fields2['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
    $fields2['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
    var_dump($fields2);
    //return $fields2;
}
</code></pre>