skip to Main Content

in the checkout of my Woocommerce-Shop is a dropdown to choose your country.
On default the USA is automatically selected already.
How to just have a placeholder with “select your country” instead?

I couldn’t find any solution to this topic somebody have any idea?

I changed the other Placeholders which aren’t Dropdowns but are inside the same form:

add_filter( 'woocommerce_checkout_fields' , 'override_billing_checkout_fields', 20, 1 );
function override_billing_checkout_fields( $fields ) {
    $fields['billing']['billing_first_name']['placeholder'] = 'First Name*';
    $fields['billing']['billing_last_name']['placeholder'] = 'Last Name*';
    $fields['billing']['billing_city']['placeholder'] = 'Town / City*';
    $fields['billing']['billing_postcode']['placeholder'] = 'ZIP*';
    $fields['billing']['billing_email']['placeholder'] = 'Email Address*';
    return $fields;
}

My poor solution for now is: I created a new “Country in the Dropdown List” which I just named: select your country* and then just selected it on default instead of the USA. But the problem is here that the system thinks a real country is chosen already so it’s not a mandatory field anymore and also the fact that it just doesn’t look usual for the user when they choose their country:

function woo_add_my_country( $country ) {
   $country["PLACE"] = 'select your country*';
   return $country;
}
add_filter( 'woocommerce_countries', 'woo_add_my_country', 10, 1 );


add_filter( 'default_checkout_billing_country', 'bbloomer_change_default_checkout_country' );

function bbloomer_change_default_checkout_country() {
  return 'PLACE'; 
}

I would appreciate any help or tips!

3

Answers


  1. This is working for my side try this

    // Change the default country and state on checkout page. 
    // This works for a new session.
    add_filter( 'default_checkout_country', 'xa_set_default_checkout_country' );
    add_filter( 'default_checkout_state', 'xa_set_default_checkout_state' );
    function xa_set_default_checkout_country() {
      // Returns empty country by default.
        return null;
      // Returns India as default country.
         // return 'IN';
    }
    
    function xa_set_default_checkout_state() {
      // Returns empty state by default.
        return null;
      // Returns Madhya Pradesh as default state.
         // return 'MP';
    }
    function woo_add_my_country( $country ) {
       $country["PLACE"] = 'select your country*';
       return $country;
    }
    add_filter( 'woocommerce_countries', 'woo_add_my_country', 10, 1 );
    
    
    add_filter( 'default_checkout_billing_country', 'bbloomer_change_default_checkout_country' );
    
    function bbloomer_change_default_checkout_country() {
      return 'PLACE'; 
    }
    
    Login or Signup to reply.
  2. Just go to WooCommerce > Settings.
    On General tab you will find Default customer location. Set it to No location by default

    enter image description here

    Login or Signup to reply.
  3. This was one of the first results that popped up for me when searching how to set a placeholder for a select field on the Woocommerce checkout page, so for any future visitors:

    I have a company select field that I populate dynamically with values from the database. In order to set a placeholder value, I just add an option with a blank value.

    add_filter( 'woocommerce_checkout_fields' , 'populate_company_field' );
    function populate_company_field($fields) {
      $results = get_results_from_database();
      $options[''] = __('Choose your company', 'gs'); //add blank value = placeholder
    
      foreach ($results as $result) {
        if (!empty($result->company)) {
            $options[$result->ID] = $result->company;
        }
      }
    
      $fields['billing']['company']['options'] = $options;
    
      return $fields;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search