WooCommerce 2.6 – Hide shipping methods when FREE SHIPPING is availableVj
WooCommerce 2.6 brings major changes in the shipping module including the introduction of Shipping Zone.
These changes break the number of existing snippets including the snippet to Hide shipping methods when FREE SHIPPING is available.
This is because of minor changes in the way
$rates array is formed for the shipping method “Free Shipping”. Prior to WooCommerce 2.6, the details of shipping method “Free Shipping” is stored under array element
$rates['free_shipping']. Now it is stored as
shipping_zone_instance_id is the shipping zone instance id of the shipping method.
Means, if the instance id of shipping zone is 1, the rates array key will be
free_shipping:1 and if instance id of shipping zone is 2, then the rates array key will be
free_shipping:2 and so on.
Please refer this article for more details on shipping zones and to get an idea of instance id.
Code Snippet to Hide shipping methods when FREE SHIPPING is available.
Below snippet is an effort to make the existing snippet work for WooCommerce 2.6. Let me know in comments if this can be improved. Alternatively, you can use ELEX WooCommerce Hide Shipping Method Plugin to conditionally hide WooCommerce shipping methods.