Here’s a step-by-step tutorial on how to hide other shipping methods when “Free Shipping” is available in WooCommerce:
/wp-admin
to the end of your website URL.If you don’t want to modify your theme’s functions.php
file directly, you can use a code snippets plugin to add custom code to your site.
You can either:
functions.php
file.Paste the following code into the functions.php
file or the code snippet editor:
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
If you’re using a caching plugin or a content delivery network (CDN), clear the cache to make sure the changes reflect properly on your live site.
That’s it! You’ve successfully hidden other shipping methods when free shipping is available in WooCommerce.
POST A COMMENT