Hide Other Shipping Methods When Free Shipping is Available (WooCommerce)
March 16, 2025 | 9:18 AM
Here’s a step-by-step tutorial on how to hide other shipping methods when “Free Shipping” is available in WooCommerce:
Step 1: Log into Your WordPress Admin Dashboard
- Go to your WordPress website’s backend by adding
/wp-admin
to the end of your website URL. - Enter your credentials to log in.
Step 2: Install a Code Snippet Plugin (Optional)
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.
- In the WordPress dashboard, go to Plugins > Add New.
- Search for “Code Snippets” and install the plugin.
- After installation, activate the plugin.
Step 3: Navigate to the Theme Editor or Code Snippets
You can either:
- Go to Appearance > Theme File Editor and open your active theme’s
functions.php
file. - Or, if using a Code Snippets plugin, go to Snippets > Add New.
Step 4: Add the Custom Code
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 );
Step 5: Save Changes
- If you’re using the theme editor, click the Update File button to save your changes.
- If you’re using the Code Snippets plugin, save the snippet and activate it.
Step 6: Test the Changes
- Go to your WooCommerce store.
- Add a product to the cart that qualifies for free shipping.
- Proceed to the checkout page and ensure that only the free shipping option is visible, hiding all other shipping methods like flat rate or local pickup.
Step 7: Clear Cache
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.
Additional Notes:
- This code only hides other shipping methods when free shipping is available in the same shipping zone.
- Make sure that your Free Shipping is configured correctly under WooCommerce > Settings > Shipping > Shipping Zones.
That’s it! You’ve successfully hidden other shipping methods when free shipping is available in WooCommerce.