NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

WooCommerce: Disabling Shipping Charges When Offering Free Shipping
Intermediate

---- Last modified : Oct 01 2022

Estimated reading time : 1 minute, 31 seconds - 166 words

With this tutorial, we will show you how to disable shipping charges when you want to offer free shipping. For example, with WooCommerce you can add a rule where if customers orders for a minimum 75$, they can get free shipping.

The problem is that WooCommerce leaves all types of shipping charges as default settings. So it can leave customers confused as they might not understand if shipping is free or not. Additionally, they cannot select a different shipping method.

Here’s a function that will help you disable shiping charges. First, you’ll notice that both values are displayed in the unset with Firebug. Note the values with their number.

In the images above, you’ll notice each input for each shipping charge.
In the first one, we can see free_shipping:9, whereas with the shipping charge input, we can see flat_rate:6. So with this function, we will say that if the shiping method works, disable all other shipping methods.

add_filter( 'woocommerce_package_rates', 'montheme_unset_shipping_when_free_is_available_in_zone', 10, 2 );
function montheme_unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
    // Only unset rates if free_shipping is available
    if ( isset( $rates['free_shipping:9'] ) ) {
    unset( $rates['flat_rate:6'] );
}   
    return $rates;
}

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>