WooCommerce stores are very easy to manage and moderate, whether you are good on the technical side or not. Moreover, it has a user-friendly back end that has a plethora of options to tweak your store.
It is worth mentioning that shipping is an inseparable operation if you want to have a successful online store. With increasing locations and setups for the shipping processes, you keep adding shipping methods to your store. For local customers residing near your physical stores and warehouses, you can introduce free shipping or local pickup facilities.
However, one thing is clear here. The increasing shipping method and their availability on the cart page, even when not required, could be adversely affecting your site’s user experience or confusing the buyers. This, in turn, reduces the sales in your WooCommerce store.
For example, if Free Shipping is available, you may not want to show the other paid shipping options. WooCommerce, by default, displays all the shipping rates that match a given shipping zone, so it is not possible to achieve this from the settings alone. You need PHP for that.
In this tutorial, I will show you how to disable all shipping methods but “Free Shipping” so that free shipping remains the only possible choice.
Steps to Hide Shipping Rates if Free Shipping is Available
Here are the steps that you need to follow:
- Log into your WordPress site and access the Dashboard as the admin user.
- From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to unset specific shipping rate when free shipping rate is available.
- Add the following code to the functions.php file:
/** * Hide one shipping option in one zone when Free Shipping is available */ add_filter( 'woocommerce_package_rates', 'njengah_unset_shipping_when_free_is_available_in_zone', 10, 2 ); function njengah_unset_shipping_when_free_is_available_in_zone( $rates, $package ) { // Only unset rates if free_shipping is available if ( isset( $rates['free_shipping:8'] ) ) { unset( $rates['flat_rate:1'] ); } return $rates; }
- The next step is to unset all shipping rates in all zones when any free shipping rate is available. This can be achieved by adding the following code to the functions.php file:
/** * Hide ALL shipping rates in ALL zones when Free Shipping is available */ add_filter( 'woocommerce_package_rates', 'njengah_unset_shipping_when_free_is_available_all_zones', 10, 2 ); function njengah_unset_shipping_when_free_is_available_all_zones( $rates, $package ) { $all_free_rates = array(); foreach ( $rates as $rate_id => $rate ) { if ( 'free_shipping' === $rate->method_id ) { $all_free_rates[ $rate_id ] = $rate; break; } } if ( empty( $all_free_rates )) { return $rates; } else { return $all_free_rates; } }
Conclusion
This post shows how you can hide the shipping rates if the Free Shipping method is available. The first thing you need to do is to unset the specific shipping rate when a free shipping rate is available. The next step is to unset all shipping rates in all zones when any free shipping rate is available. If the shipping rates are not working after implementing the PHP code snippets, empty the cart and start testing again.
Similar Articles
- How to Change Storefront Theme Product Page Tabs Colors
- How to Add Sub Menu to Custom Post Type Menu in WordPress
- How to Hide the WooCommerce Coupon Code Field
- How to Add Description after Price in WooCommerce
- How to Remove Zoom Effect on WooCommerce Product Image
- How to Add Custom Shipping Method in WooCommerce
- How to Add WooCommerce Storefront Banner
- WooCommerce Redirect Users After Registration by Roles
- How to Add Text after Price in WooCommerce » Add Price Suffix
- How to Remove Has Been Added to Your Cart Message WooCommerce
- How to Logout without Confirmation WooCommerce: How to Remove “Are you sure you want to log out?”
- How to Change Out Of Stock Text in WooCommerce
- How to Skip Cart and Redirect to Checkout Page WooCommerce
- How to Remove or Rename Sale Badge WooCommerce Storefront
- How to Put WooCommerce Cart and Checkout on One Page
- How to Redirect User If Not Logged in WordPress » Page Redirect
- How to Remove Cart Page WooCommerce Storefront Theme
- How Add Text Before the Price in WooCommerce » Add Text Before Price
- How to Set Up WooCommerce Storefront Shipping Quick Guide
- How to Move Primary Menu Storefront WooCommerce