John Davidson

php - Set a default value for shipping city and state in Woocommerce My account

0 comments
Message:


In woocommerce already the shipping country in restricted to IN
On checkout the default value of Country, state & city is set
I want to do that same in my-account/edit-address/ only in shipping address
tried using this code but its not working


add_filter( 'woocommerce_shipping_fields' , 'default_shipping_address' );

function default_shipping_address( $fields ) {
$fields['shipping_city']['default'] = 'Mumbai';
$fields['shipping_state']['default'] = 'Maharashtra';
return $fields;

}

this is not working let me know what's wrong or is there any other way to do this?




My Answer:
and city can be set using the following code snippet:

php
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_billing_state', 'change_default_checkout_state' );
add_filter( 'default_checkout_billing_city', 'change_default_checkout_city' );

function change_default_checkout_country() {
return 'IN'; // Set default country to India
}

function change_default_checkout_state() {
return 'DL'; // Set default state to Delhi
}

function change_default_checkout_city() {
return 'New Delhi'; // Set default city to New Delhi
}


You can add this code to your theme's functions.php file or a custom plugin to set the default values for shipping city and state in WooCommerce checkout page.

Rate this post

5 of 5 based on 3959 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us