At times, you may desire to modify the display of shipping methods, for example, hiding shipping method ‘B’ when shipping method ‘A’ is available. The following code allows customers to show free express delivery and hide the paid express delivery option, only when the free shipping option is available. If the free express delivery is unavailable, the alternative shipping method will be displayed.
add_filter( 'woocommerce_package_rates', 'ts_customizing_shipping_methods', 10, 2 ); function ts_customizing_shipping_methods( $rates, $package ) { $flat_express_delivery_rate_id = 'flat_rate:4'; // Paid delivery by express mail (cost $35) $free_express_delivery_rate_id = 'free_shipping:5'; // Free delivery by express mail // When Free delivery by express mail is available if( isset($rates[$free_express_delivery_rate_id]) ) { // Remove Paid delivery by express mail (cost $35) unset($rates[$flat_express_delivery_rate_id]); } return $rates; }
Output
Consider that the shipping methods present in the below image are the available shipping options.
![How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? 1 How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/available-shiping-options-1024x415.png)
If the free express delivery method is present in the $rates
array, it removes (hides) the paid express delivery method.
![How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? 2 How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/removed-shipping-based-on-conditions-1024x988.png)
Now, let’s assume that free shipping is not one of the available shipping options.
![How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? 3 How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/disable-free-shipping-1024x464.png)
Whenever the free shipping option is not available, only then the paid delivery express mail will be shown in the shipping methods.
![How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? 4 How to Hide Selected Shipping Methods When Free Shipping is Available in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/display-shipping-based-on-certain-conditions-1024x997.png)
Here we are hiding selective shipping method when free shipping is available. But you can also refer to this post that will hide all other shipping methods when free shipping is available which covers different scenarios in hiding shipping methods.