MiraTech
MiraTech

Reputation: 1352

Change billing address fields type woocommercce

I want to change the type of some fields in my account page, where i want to change City from "textfield" to <select> (list) where I specify only some cities, I don't want users to type anything, do you have any idea on which code shall I edit?
I tried with this but I don't know what to modifie!

I want only three cities to be selected (Paris, London, Algiers)

add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

    function custom_woocommerce_billing_fields( $fields ) {

       $fields['billing_city']  = array(
          'label'          => __('City', 'woothemes'),
          'placeholder'    => __('City', 'woothemes'),
          'required'       => true,
          'class'          => array('billing-city')
       );

     return $fields;
    }

Thank you in advanced!

Upvotes: 0

Views: 240

Answers (1)

Purvik Dhorajiya
Purvik Dhorajiya

Reputation: 4880

Can you please try below code.

add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

function custom_woocommerce_billing_fields( $fields ) {

   $fields['billing_city']  = array(
      'type'            => 'select',
      'label'          => __('City', 'woothemes'),
      'placeholder'    => __('City', 'woothemes'),
      'required'       => true,
      'class'          => array('billing-city'),
      'options'     => array(
            'paris' => __('Paris', 'woothemes' ),
            'london' => __('London', 'woothemes' ),
            'algiers' => __('Algiers', 'woothemes' )
        )
   );

 return $fields;
}

Upvotes: 1

Related Questions