• Resolved fastfingaz

    (@fastfingaz)


    Hi,

    I’m trying to hide the Town/City field for certain states when they are selected. Can anyone provide me with a working code snippet to do this?

    For example, if a customer selects Massachusetts as State on the Checkout page, the Town/City field should be hidden or not required.

    I’m looking to do this for multiple states in the same country.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Saravanan S, a11n

    (@simplysaru)

    Hey there @fastfingaz,

    You are able to use a plugin like this to create conditions for checkout fields.

    Thread Starter fastfingaz

    (@fastfingaz)

    Thanks for the response @simplysaru. However, this doesn’t solve my challenge. I really wish I could get a code snippet. Been crawling through the internet all to no avail. I hope someone comes through for me

    Thread Starter fastfingaz

    (@fastfingaz)

    I had to implement a solution I didn’t want to. Here is what I did below.

    Instead of hiding the Town/City field for some States, I added a city per State for those States using the Plugin Shipping by City for Woocommerce. The States had been declared in Woocommerce Shipping Zones already.

    Then I installed the WC City Select Plugin to turn the Town/City field into a dropdown list.

    To make the WC City Select Plugin work, I added the required code as instructed by the Plugin Author in the functions.php file of my child theme and tweaked to my satisfaction.

    Here is the code snippet

    /**
     * Replace XX with the country code. Instead of YYY, ZZZ use actual state codes.
     */
    
    add_filter( 'wc_city_select_cities', 'my_cities' );
    function my_cities( $cities ) {
    	$cities['XX'] = array(
    		'YYY' => array(
    		'City 1',
    		'City 2'
    	   )
    	);
    	return $cities;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide Town/City Field For Certain States’ is closed to new replies.