Are you shipping only to a limited number of states from a specific country? This customization allows you to exclude certain states from being displayed during the checkout process in WooCommerce.
add_filter( 'woocommerce_states', 'ts_custom_us_states', 10, 1 ); function ts_custom_us_states( $states ) { $non_allowed_us_states = array( 'IN', 'CA', 'CO', 'IL'); // Loop through your non allowed us states and remove them foreach( $non_allowed_us_states as $state_code ) { if( isset($states['US'][$state_code]) ) unset( $states['US'][$state_code] ); } return $states; }
Output
If the customer selects the United States as their country, the dropdown field will omit certain states as specified in the code.
Read Related Article: How to Remove All Taxes in WooCommerce for a Minimum Cart Total and Specific Countries?
Are you more focused on local deliveries, restricting shipping to only one state? Then this guide will help you to limit shipping to only one state with WooCommerce.
Will this remove the given states from ONLY the shipping details area or BOTH the billing details and shipping details areas?
Hi Dylan,
The code will remove the given states from both the billing and shipping state fields. For targeting any one of these state fields, the hook should be changed.
Do you happen to know how the hook would need to be changed to take the given state out of ONLY the shipping details?
This is the specific hook ‘woocommerce_states_shipping’ to remove the given states only from the shipping state fields.