Home » Tutorials » Hide Other Shipping Methods When Free Shipping is Available (WooCommerce)

Hide Other Shipping Methods When Free Shipping is Available (WooCommerce)

Hide Other Shipping Methods When Free Shipping is Available (WooCommerce)

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

  1. Go to your WordPress website’s backend by adding /wp-admin to the end of your website URL.
  2. 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.

  1. In the WordPress dashboard, go to Plugins > Add New.
  2. Search for “Code Snippets” and install the plugin.
  3. 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

  1. If you’re using the theme editor, click the Update File button to save your changes.
  2. If you’re using the Code Snippets plugin, save the snippet and activate it.

Step 6: Test the Changes

  1. Go to your WooCommerce store.
  2. Add a product to the cart that qualifies for free shipping.
  3. 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.

How to Hide Other Shipping Methods When Free Shipping is Available in WooCommerce – Quick Youtube Video Tutorial

How to Hide Other Shipping Methods When Free Shipping is Available in WooCommerce - Quick Youtube Video Tutorial

    POST A COMMENT

    Your email address will not be published. Required fields are marked *

    Bloggy Master On YouTube
    Sri Venkateswara Swamy Temple Jubilee Hills Hyderabad
    Shri Jagannath Temple, Hyderabad
    Birla Temple Hyderabad: Architecture, History, Timings, Location
    Birla Mandir
    NTR Gardens Video