How to add Puerto Rico back as a US state in WooCommerce and remove it as a country

I have seen many requests from folks asking how to add Puerto Rico back as a state option and remove it as a country from WooCommerce, this largely due to some postal services still listing Puerto Rico as a state, which makes shipping cheaper.

According to the ISO 3166 standard, however, PR has a country code and should be listed as such:

https://en.wikipedia.org/wiki/ISO_3166-1

If you really need to change it back to showing as a state, you can use the following code. It will remove Puerto Rico as a country, re-add it as a US state, and it will display correctly throughout your site, in the cart, checkout, and shipping zones.

add_filter( 'woocommerce_countries', 'wc_remove_pr_country', 10, 1 );

function wc_remove_pr_country ( $country ) {
   unset($country["PR"]);
   return $country; 
}

add_filter( 'woocommerce_states', 'wc_us_states_mods' );

function wc_us_states_mods ( $states ) {

  $states['US'] = array(
          'AL' => __( 'Alabama', 'woocommerce' ),
          'AK' => __( 'Alaska', 'woocommerce' ),
          'AZ' => __( 'Arizona', 'woocommerce' ),
          'AR' => __( 'Arkansas', 'woocommerce' ),
          'CA' => __( 'California', 'woocommerce' ),
          'CO' => __( 'Colorado', 'woocommerce' ),
          'CT' => __( 'Connecticut', 'woocommerce' ),
          'DE' => __( 'Delaware', 'woocommerce' ),
          'DC' => __( 'District Of Columbia', 'woocommerce' ),
          'FL' => __( 'Florida', 'woocommerce' ),
          'GA' => _x( 'Georgia', 'US state of Georgia', 'woocommerce' ),
          'HI' => __( 'Hawaii', 'woocommerce' ),
          'ID' => __( 'Idaho', 'woocommerce' ),
          'IL' => __( 'Illinois', 'woocommerce' ),
          'IN' => __( 'Indiana', 'woocommerce' ),
          'IA' => __( 'Iowa', 'woocommerce' ),
          'KS' => __( 'Kansas', 'woocommerce' ),
          'KY' => __( 'Kentucky', 'woocommerce' ),
          'LA' => __( 'Louisiana', 'woocommerce' ),
          'ME' => __( 'Maine', 'woocommerce' ),
          'MD' => __( 'Maryland', 'woocommerce' ),
          'MA' => __( 'Massachusetts', 'woocommerce' ),
          'MI' => __( 'Michigan', 'woocommerce' ),
          'MN' => __( 'Minnesota', 'woocommerce' ),
          'MS' => __( 'Mississippi', 'woocommerce' ),
          'MO' => __( 'Missouri', 'woocommerce' ),
          'MT' => __( 'Montana', 'woocommerce' ),
          'NE' => __( 'Nebraska', 'woocommerce' ),
          'NV' => __( 'Nevada', 'woocommerce' ),
          'NH' => __( 'New Hampshire', 'woocommerce' ),
          'NJ' => __( 'New Jersey', 'woocommerce' ),
          'NM' => __( 'New Mexico', 'woocommerce' ),
          'NY' => __( 'New York', 'woocommerce' ),
          'NC' => __( 'North Carolina', 'woocommerce' ),
          'ND' => __( 'North Dakota', 'woocommerce' ),
          'OH' => __( 'Ohio', 'woocommerce' ),
          'OK' => __( 'Oklahoma', 'woocommerce' ),
          'OR' => __( 'Oregon', 'woocommerce' ),
          'PA' => __( 'Pennsylvania', 'woocommerce' ),
          'PR' => __( 'Puerto Rico', 'woocommerce' ),
          'RI' => __( 'Rhode Island', 'woocommerce' ),
          'SC' => __( 'South Carolina', 'woocommerce' ),
          'SD' => __( 'South Dakota', 'woocommerce' ),
          'TN' => __( 'Tennessee', 'woocommerce' ),
          'TX' => __( 'Texas', 'woocommerce' ),
          'UT' => __( 'Utah', 'woocommerce' ),
          'VT' => __( 'Vermont', 'woocommerce' ),
          'VA' => __( 'Virginia', 'woocommerce' ),
          'WA' => __( 'Washington', 'woocommerce' ),
          'WV' => __( 'West Virginia', 'woocommerce' ),
          'WI' => __( 'Wisconsin', 'woocommerce' ),
          'WY' => __( 'Wyoming', 'woocommerce' ),
          'AA' => __( 'Armed Forces (AA)', 'woocommerce' ),
          'AE' => __( 'Armed Forces (AE)', 'woocommerce' ),
          'AP' => __( 'Armed Forces (AP)', 'woocommerce' ),
  );

  return $states;
}

You can add this code to your site following the instructions here:

How to add custom code to your WooCommerce/WordPress site the right way

Have any feedback? Be sure to let me know here: Contact me

2 thoughts on “How to add Puerto Rico back as a US state in WooCommerce and remove it as a country

  1. Wow, Finally, I’ve been having issues with Shippo+Woo Commerce Integration because of Puerto Rico’s towns, + Country either being left blank, or appearing somewhere else once the order was placed, also happened to a few customer receipts as well where the info was misplaced billing for shipping and vice-versa. Will try this tomorrow early in the morning on my staging site and hope this solves ( it should solve the shipping issue) as it is USPS and PR ships through them to the USA. Hope to keep my client happy,

    Eres el duro Rynaldo, Gracias!!

    -Saludos desde San Juan

  2. Would adding USVI work as well in the same manner? I’m thinking I can add : ‘USVI’ => __( ‘Virgin Islands’, ‘woocommerce’ ),

    would it work like this ? thanks

Share your thoughts

Your email address will not be published. Required fields are marked *