Change Address Checkout Field Into Drop-down

If you Want to sell the Products to specific areas and you want to minimize the writing time – why not let customers pick from a list instead? To do so you need to turn the “Address 2” field into a dropdown. You can add the following Snippet to your Functions.php.

add_filter( 'woocommerce_default_address_fields' , 'codeithub_address_field_dropdown' );
 
function codeithub_address_field_dropdown( $address_fields ) {
 
    $location_array = array(
      'Location 1' => 'Location 1',
      'Location 2' => 'Location 2',
      'Location 3' => 'Location 3',
      'Location 4' => 'Location 4',
    );
 
$address_fields['address_2']['label'] = 'Location';
$address_fields['address_2']['type'] = 'select';
$address_fields['address_2']['options'] = $location_array;
 
return $address_fields;
 
}

Before:

See also  How to Show SKU Code on WooCommerce Cart Page
Default Address Field

After:

Dropdown Address Field

Leave a Reply

Your email address will not be published. Required fields are marked *