Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to set default checkout billing city WordPress

  • SOLVED

I tried following code but

It's not working for me.

function default_checkout_city(){
return 'x'; // state code
}//add_filter( 'woocommerce_countries_base_city', 'default_checkout_city' );

add_filter( 'woocommerce_countries_base_city' , 'set_woocommerce_countries_base_city' );
function set_woocommerce_countries_base_city() {
// Replace with your store town/city
return 'x';
}

Answers (2)

2016-10-30

Bob answers:

Not sure about the exact code for this right now but there is one hack.
You can make city field drop down and add only one city you needed there.
If you wish you can set it as required field too.

add_filter( 'woocommerce_default_address_fields' , 'bha_override_default_address_fields' );
function bha_override_default_address_fields( $address_fields ) {

// Billing City
$address_fields['city']['type'] = 'select';
$address_fields['city']['options'] = array(
'Your City' => 'Your City',
);
return $address_fields;
}


email889 comments:

I am happy with this option. Thanks

2016-10-30

Fahad Murtaza answers:

Hi

Have you tried woocommerce_default_address_fields yet ?

[[LINK href="https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2"]]https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2[[/LINK]]


email889 comments:

I tried ['default'] that but it created a new field instead of set default value.

Can you give a complete code for test? TO check if we are on the same page. Thanks


Fahad Murtaza comments:

OK

I am working on it. For testing, I'd install woocommerce right now.