-1

I have used following code to add custom state field to WooCommerce checkout field

add_action( 'woocommerce_after_order_notes', 'some_custom_checkout_field' );

function some_custom_checkout_field( $checkout ){
  echo '<div id="some_custom_checkout_field"><h2>' . __('Heading') . '</h2>';
    woocommerce_form_field( 'some_field_name', array(

       'type'         => 'state',
       'class'         => array('my-field-class form-row-wide'),
       'label'         => __('Additional Field'),
       'required'     => true,
     ), $checkout->get_value( 'some_field_name' ));

  echo '</div>';
}

My Problem:
When I visit to checkout page for the first time it always create a TEXT BOX instead a State Drop Down, if I refresh the page it works just fine.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Shravan Sharma
  • 989
  • 8
  • 17

1 Answers1

0

If you want to add extra field at checkout form, you need to use hook woocommerce_checkout_fields also you need to define type as "select". I used this code to add extra field and customise checkout page.

https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-3

Bhunesh Satpada
  • 770
  • 1
  • 6
  • 19