Change State Name to Postal Abbreviation in WooCommerce


On 03-29-2018 articles, code, WooCommerce

Changing the states names to abbreviations in Woocommerce is pretty easy. There are a couple references online that tell you how to do this but they don’t actually supply the whole list of states in their sample. This is for US states based on WooCoomerce 3.3.4, but should work for older versions. You can file the state list in your WooCommerce plugin folder @ /plugins/woocommerce/i18n/states

A simple copy and paste job will do the trick!

add_filter( 'woocommerce_states', 'lets_customize_woocommerce_states' );
    function lets_customize_woocommerce_states() {
    	global $states;

    	$states['US'] = array(
                'AL' =>	__( 'AL' , 'woocommerce' ),
        	'AK' =>	__( 'AK' , 'woocommerce' ),
        	'AZ' =>	__( 'AZ' , 'woocommerce' ),
        	'AR' =>	__( 'AR' , 'woocommerce' ),
        	'CA' =>	__( 'CA' , 'woocommerce' ),
        	'CO' =>	__( 'CO' , 'woocommerce' ),
        	'CT' =>	__( 'CT' , 'woocommerce' ),
        	'DE' =>	__( 'DE' , 'woocommerce' ),
        	'DC' =>	__( 'DC' , 'woocommerce' ),
        	'FL' =>	__( 'FL' , 'woocommerce' ),
        	'GA' =>	_x( 'GA' , 'woocommerce' ),
        	'HI' =>	__( 'HI' , 'woocommerce' ),
        	'ID' =>	__( 'ID' , 'woocommerce' ),
        	'IL' =>	__( 'IL' , 'woocommerce' ),
        	'IN' =>	__( 'IN' , 'woocommerce' ),
        	'IA' =>	__( 'IA' , 'woocommerce' ),
        	'KS' =>	__( 'KS' , 'woocommerce' ),
        	'KY' =>	__( 'KY' , 'woocommerce' ),
        	'LA' =>	__( 'LA' , 'woocommerce' ),
        	'ME' =>	__( 'ME' , 'woocommerce' ),
        	'MD' =>	__( 'MD' , 'woocommerce' ),
        	'MA' =>	__( 'MA' , 'woocommerce' ),
        	'MI' =>	__( 'MI' , 'woocommerce' ),
        	'MN' =>	__( 'MN' , 'woocommerce' ),
        	'MS' =>	__( 'MS' , 'woocommerce' ),
        	'MO' =>	__( 'MO' , 'woocommerce' ),
        	'MT' =>	__( 'MT' , 'woocommerce' ),
        	'NE' =>	__( 'NE' , 'woocommerce' ),
        	'NV' =>	__( 'NV' , 'woocommerce' ),
        	'NH' =>	__( 'NH' , 'woocommerce' ),
        	'NJ' =>	__( 'NJ' , 'woocommerce' ),
        	'NM' =>	__( 'NM' , 'woocommerce' ),
        	'NY' =>	__( 'NY' , 'woocommerce' ),
        	'NC' =>	__( 'NC' , 'woocommerce' ),
        	'ND' =>	__( 'ND' , 'woocommerce' ),
        	'OH' =>	__( 'OH' , 'woocommerce' ),
        	'OK' =>	__( 'OK' , 'woocommerce' ),
        	'OR' =>	__( 'OR' , 'woocommerce' ),
        	'PA' =>	__( 'PA' , 'woocommerce' ),
        	'RI' =>	__( 'RI' , 'woocommerce' ),
        	'SC' =>	__( 'SC' , 'woocommerce' ),
        	'SD' =>	__( 'SD' , 'woocommerce' ),
        	'TN' =>	__( 'TN' , 'woocommerce' ),
        	'TX' =>	__( 'TX' , 'woocommerce' ),
        	'UT' =>	__( 'UT' , 'woocommerce' ),
        	'VT' =>	__( 'VT' , 'woocommerce' ),
        	'VA' =>	__( 'VA' , 'woocommerce' ),
        	'WA' =>	__( 'WA' , 'woocommerce' ),
        	'WV' =>	__( 'WV' , 'woocommerce' ),
        	'WI' =>	__( 'WI' , 'woocommerce' ),
        	'WY' =>	__( 'WY' , 'woocommerce' ),
        	'AA' =>	__( 'AA' , 'woocommerce' ),
        	'AE' =>	__( 'AE' , 'woocommerce' ),
        	'AP' =>	__( 'AP' , 'woocommerce' )
    	);
    	
    	return $states;
    }