How to have free shipping for WooCommerce Membership members

If you are open to using a plugin to achieve this, then the Advanced Free Shipping” plugin by Jeroen Sormani can definitely help you.
Using this, you can provide free shipping based on the user role. In that case, you can simply create a new user role that will be used to identify the users.

It’s in the wordpress plugin directory and is free : https://wordpress.org/plugins/woocommerce-advanced-free-shipping/

EDIT —

Thought you were trying to base it through WP user roles. There’s actually a way to identify the current user’s membership plan and at the same time to unset the other woocommerce shipping rates/method. Based on the docs, we might be able to achieve what you need by doing something like this.

    add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

    function hide_shipping_when_free_is_available( $rates, $package ) {

    // Get current user ID
    $user_id = get_current_user_id();

    // Let's use a hook based o https://docs.woocommerce.com/document/woocommerce-memberships-function-reference/
   // This is assuming that the plan's name is "gold"
   if (wc_memberships_is_user_active_member( $user_id, 'gold' )) {

   // If the user is active, then let's force the free shipping method
    $free_shipping          = $rates['free_shipping'];
    $rates                  = array();
    $rates['free_shipping'] = $free_shipping;
   }
   return $rates;
   }

This is from a sample in woocommerce. Only, we modified the if statement a bit.

tech