如果另一个可用,则隐藏一种交付方式Woocommerce

I have two free shipping methods.

The first - in the city, it becomes free from $ 50. The second is outside the city, it becomes free from $ 70. Thus, when a client has an order for more than $ 70, all 4 delivery methods are available to him (for a city it is paid, for a city is free, outside the city is paid and outside the city is free).

It is necessary for me, when a free delivery method in the city is available, the paid delivery method in the city must be hidden. and when the free delivery method is available outside the city, then the paid delivery method outside the city must be hidden.

I apologize for the poor English and I ask for your help.

I tried it like this, but it doesn't work.

function hide_shipping( $rates ) {
    if (isset( $rates['free_shipping:3'] ) ) {
      unset( $rates['flat_rate:1'] );
    }
    if (isset( $rates['free_shipping:9'] ) ) {
      unset( $rates['local_pickup:7'] );
    }
  return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping', 10, 2 );

Everything is correct, the code is working! I did not notice myself with an error. I apologize :)