I'm have been searching for solution for this in google but I have not found any. Is there a way to hide some state if a coupon its active?
I found "Remove specific states of a country on Woocommerce Checkout" answer code that works with payment gateways and I´m trying to adapt the code for states:
add_filter('woocommerce_states', 'applied_coupons_hide_states', 20, 1 );
function applied_coupons_hide_states( $states){
if( sizeof( WC()->cart->get_applied_coupons() ) > 0 ){
foreach ( $states as $state_key => $state_value ) {
if( $state_key != 'LMA,LIM' )
unset($states[$state_key]);
}
}
return $states;
}
But I can't make it work. What I am doing wrong?
Any help is appreciated.