• Resolved zikrainfotech

    (@zikrainfotech)


    Hi, I am developing a delivery website and I deliver only in one city, so during the checkout I want to add the city and state name by default and not give the user the option to edit it: https://prnt.sc/214teks – check this right now it’s editable
    If you check here the country option is set as default – https://prnt.sc/21f6qjh in my checkout flow.

    I have searched and tried many codes from stack overflow and WooCommerce docs, somewhere I am doing a mistake!

    Kindly help me out – share a code that I can add in my functions.php file of my theme editor which will make both the billing and shipping values of city and state as KADAPA and ANDHRA PRADESH respectively!

    Currently, I am trying to add this piece of code in my theme editor’s function.php file, but it is not working:

    add_filter( 'default_checkout_billing_city', 'change_default_checkout_city' );
    add_filter( 'default_checkout_billing_state', 'change_default_checkout_state' );
    
    function change_default_checkout_city() {
      return 'Kadapa'; // country code
    }
    
    function change_default_checkout_state() {
      return 'Andhra Pradesh'; // state code
    }

    I will be really grateful!

    Site URL: https://expressmeatmart.com/
    Xstore Theme version: 8.0.10
    WooCommerce version: 5.9.0

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello there ??

    Please visit this article:
    How to Set the Default City at Checkout

    I hope this helps.

    Thread Starter zikrainfotech

    (@zikrainfotech)

    Hey, thanks for the post link:

    I used that code:

    add_filter( 'woocommerce_checkout_fields', 'bbloomer_set_checkout_field_input_value_default' );
     
    function bbloomer_set_checkout_field_input_value_default($fields) {
        $fields['billing']['billing_city']['default'] = 'Kadapa';
    	$fields['billing']['billing_state']['default'] = 'Andhra Pradesh';
        return $fields;
    }

    The city name changed, but it was still editable

    But the state name did not change, we want both the state and city name to be not editable. Please guide!

    @zikrainfotech

    A similar solution was provided here. Could you check that?

    Thread Starter zikrainfotech

    (@zikrainfotech)

    Thanks!

    I tried the same code, it worked for me!
    But strangely there is a gap in the dropdown and their width also reduced, how can I remove the gap and increase the width

    Here are the screenshots from my checkout page: [https://prnt.sc/21ky0df][1]

    [https://prnt.sc/21ky46v][2]

    [1]: https://prnt.sc/21ky0df
    [2]: https://prnt.sc/21ky46v

    Hello,

    how can I remove the gap and increase the width

    It’s difficult to tell without accessing the actual page, but this could be fixed with some custom CSS (adding CSS code to Appearance > Customize > Additional CSS).

    If you’d like to learn about CSS, I highly recommend using the free tutorials at w3schools. Here, you can find the basics of selectors (how to target the right element on the page), and properties (how to change the element on the page).

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need to Add a default city and state in the checkout page’ is closed to new replies.