Añadir o quitar provincias de los formularios checkout en WC

Añadir o quitar provincias de los formularios checkout en WC

Añadir o quitar provincias de los formularios checkout en WC.

/**
* Añadir o quitar provincias a los formularios del checkout
*/

function custom_woocommerce_states( $states ) {

global $woocommerce ;
if ( ! is_checkout() ) {
return $states;
}
//echo "<pre>"; print_r ($states["ES"] ); echo "</pre>";
$ebshipping_options = $_COOKIE["ebshipping_options"];

if ( $ebshipping_options == "_ebshipping_baleares" ) {
// Solo Baleares
$states["ES"] = array(
"PM" => "Baleares",
);
}
else {
// Península excepto Baleares, Ceuta, Melilla y Tenerife
if ( isset ( $states["ES"]["PM"] ) ) {
unset( $states["ES"]["PM"]);
}

if ( isset ( $states["ES"]["CE"] ) ) {
unset( $states["ES"]["CE"]);
}

if ( isset ( $states["ES"]["ML"] ) ) {
unset( $states["ES"]["ML"]);
}

if ( isset ( $states["ES"]["GC"] ) ) {
unset( $states["ES"]["GC"]);
}

if ( isset ( $states["ES"]["TF"] ) ) {
unset( $states["ES"]["TF"]);
}
}

//echo "<pre>"; print_r ($states ); echo "</pre>";
return $states;
}

add_filter( "woocommerce_states", "custom_woocommerce_states" );