Farrukh Faizy
Farrukh Faizy

Reputation: 1235

Account checkout-fields not working in woocommerce

I am designing my selected fields in woocommerce checkout-form although some work fine but the fields associated with account are not working properly. I took help from this answer but still account fields didn't load properly. enter image description here

I am using this code for generating these fields in form-billing.php

woocommerce_form_field( 'account_username', $checkout->checkout_fields['account']['account_username'],
          $checkout->get_value( 'account_username') );

woocommerce_form_field( 'account_password', $checkout->checkout_fields['account']['account_password'],
          $checkout->get_value( 'account_password') );

woocommerce_form_field( 'account_password-2', $checkout->checkout_fields['account']['account_password-2'], $checkout->get_value( 'account_password-2') );

any help would be appreciated. :)

Upvotes: 0

Views: 1939

Answers (1)

Farrukh Faizy
Farrukh Faizy

Reputation: 1235

I figured out the answer of my problem , I add filters custom_override in my themes function.php and make 3 fields of my need which is username , password and password-2 and simple call it in my form-billing.php

Add this code to my functions.php

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['account']['account_username'] = array(
        'label'     => __('Username', 'woocommerce'),
    'placeholder'   => _x('username', 'placeholder', 'woocommerce'),
    'required'  => true,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     $fields['account']['account_password'] = array(
       'type' => 'password',
       'required'  => true,
        'label' => __('Account password', 'woocommerce'),
        'placeholder' => _x('Password', 'placeholder', 'woocommerce'),
        'class' => array('form-row-wide')
     );

     $fields['account']['account_password-2'] = array(
       'type' => 'password',
       'required'  => true,
        'label' => __('Confirm your password', 'woocommerce'),
        'placeholder' => _x('Re-password', 'placeholder', 'woocommerce'),
        'class' => array('form-row-wide')

     );



     return $fields;
}

and then called my fields in my form-billing.php

woocommerce_form_field( 'account_username', $checkout->checkout_fields['account']['account_username'],
                  $checkout->get_value( 'account_username') );

woocommerce_form_field( 'account_password', $checkout->checkout_fields['account']['account_password'], $checkout->get_value( 'account_password') );

woocommerce_form_field( 'account_password-2', $checkout->checkout_fields['account']['account_password-2'], $checkout->get_value( 'account_password-2') );

Note: I override these line on this loop in form-billing.php

<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>

    <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

<?php endforeach; ?>

It solved my issue , May be it is of some help to you :)

Upvotes: 1

Related Questions