1

I cannot seem to set the default field for the country field for Woocommerce at checkout.

I am using this code from here, placing it into my functions.php of the child theme.

  add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
  function default_values_checkout_fields( $fields ) {
    // You can use this for postcode, address, company, first name, last name and such. 
    $fields['billing']['billing_country']['default'] = 'GB';
    $fields['shipping']['shipping_country']['default'] = 'GB';

    return $fields;
  }

I have tried "UK" and "United Kingdom (UK)" as values as well.

closed as off-topic by Mark Kaplun, Nathan Johnson, Jacob Peattie, cjbj, Krzysiek Dróżdż Apr 19 '18 at 7:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

4

Try this code to change the default billing country on the checkout page.

add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );


function change_default_checkout_country() {
  return 'US'; // country code
}

To change default shipping country on the checkout page

function change_set_checkout_field_input_value_default($fields) {
$fields['shipping']['shipping_country']['default'] = 'Australia';
return $fields;
}

add_filter( 'woocommerce_checkout_fields', 'change_set_checkout_field_input_value_default' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.