Hide other shipping options in WooCommerce if free shipping is available – .com

In this tutorial we are going to see how to hide other shipping options if free shipping is available in WooCommerce.

Shipping costs in WooCommerce

WooCommerce allows us to configure various shipping methods. In fact, on many occasions we will find stores that offer various possibilities to their customers: Free shipping, fixed depending on the area, or even local pickup. You can see how to configure these options in the .

Well, all this is very good since in each case you can choose the option that best suits you. However, when free shipping is being offered there is no point in having other options appear, and this is something that happens on occasion.

So let’s see how we can show only free shipping option, hiding the others, when this one is available. Go for it!.

Clear WooCommerce Cache

Before starting we will have to perform a previous step, clear the WooCommerce cache. To do this, we will go to the WordPress desktop and enter the “WooCommerce / Status” menu option.

Once here we will see three tabs, “System Status”, “Tools” and “Registry”. Well, the one that interests us is the second one, so we are going to click on it. The next screen will show us a series of available options.

From this section we can delete temporary data, reset profile capabilities, clear customer sessions, including shopping carts, or regenerate store thumbnails. In this case we will pay attention only to the two above.

To delete the cache of the products and the store, we simply have to click on “Clear temporary data” in the options “WooCommerce temporary data” and “Expired temporary data”.

See also  Digital music distribution course - .com

Then a message will appear at the top of the screen indicating the rows or data that have been deleted, and we will have it. We can move on to the next point.

Code to hide shipping methods if free shipping is available

There are several ways to hide other shipping options when free shipping is available. First of all we are going to see how to do it using code. If you do not need any extra, we advise you to do it this way since only a few lines of code will be necessary.

There are several ways to include it in our installation, we talked about it in the tutorial on . In this case we will use a plugin that we have previously created and that contains complementary functionalities, as well as some modifications of those that come by default in WooCommerce.

With that said, let’s get started. We are going to enter the WordPress dashboard and deactivate our utilities plugin. Next we will access its code through the FTP program that we usually use and we will add the snippet that we will see below.

Then we will simply have to save and activate the plugin again. By the way, comment that this code is valid for WooCommerce versions 3.0+. Well here it goes:

// Hide other shipping methods when free shipping is available. 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; break; } } return ! empty( $free ) ? $free : $rates; } add_filter( ‘woocommerce_package_rates’, ‘my_hide_shipping_when_free_is_available’, 100 );

See also  Discord course - .com

With these few lines we can get what we want, showing only the free shipping option if these are available.

In this way, we prevent customers from having to click one more time before finalizing the purchase, or from feeling confused when an option is shown that they are very likely not going to select and to which they are not going to make much sense.

Not to mention possible errors that lead to the return of shipping costs, which will generate extra workload and inconvenience to customers that would not occur if we used this code.

Although we advise you to follow the previous steps since there are very few lines of code and there is no loss, there is also the possibility of doing the same using a plugin. We will see it in the next section.

Hide other shipping options using a plugin

As we have seen, hiding the different shipping methods at checkout when free shipping is available for a purchase has interesting advantages. We can do it with code, as we just saw, and also using a plugin.

In this case we are going to install . A free plugin which will allow us to do this without writing code. To do this we have to access the WordPress dashboard, “Plugins / Add new” and enter its name in the search box.

Once it appears on the screen, we simply have to install it and activate it to start using it. Then we will enter “WooCommerce / Settings”, click on the “Shipping” tab, and finally on “Shipping Options”.

See also  Social networking course - .com

If we scroll towards the bottom of the page, we will see the new options that are available to us:

The first of these is the one that interests us in this case. In principle we will find it selected, if not, you will simply have to mark it and save the changes. And now yes, this is it.

As you can see, hiding other shipping options when free shipping is available in the client area is very easy, and you can do it both using code and with this plugin.

Summary and conclusion

WooCommerce allows you to set up multiple shipping options that can be available at once, such as fixed price, local pickup, or free shipping. When the latter is shown, it is convenient to hide the others since it does not make much sense for them to appear in that case.

To achieve this we can use a small piece of code as we have seen throughout the tutorial, or install and activate the free WC Hide Shipping Methods plugin.

And here we are! If you want to learn more, we recommend you take a look at , and . If you subscribe to you will have access to all three and many others. There are more than at your disposal 🙂

Loading Facebook Comments ...
Loading Disqus Comments ...