Website Building » WooCommerce » How Do I Hide Shipping Method in WooCommerce Checkout?

How Do I Hide Shipping Method in WooCommerce Checkout?

Last updated on January 20, 2023 @ 12:11 pm

It is very easy to hide shipping methods in WooCommerce Checkout. You just need to add a little code in your child theme’s functions.php file or in a custom plugin.

First, you need to create a function that will hide all shipping methods except for the one you want to show. You can do this by using the following code:

PRO TIP: If you are using a WooCommerce plugin to hide shipping methods in the checkout process, please be aware that this may result in unexpected charges for your customers. Shipping charges may still be applied even if the shipping method is hidden, and your customers may not be able to see these charges until they reach the final stage of checkout. We recommend only using this plugin if you are absolutely sure that shipping charges will not be applied to your customers’ orders.
function custom_hide_shipping_methods( $available_methods ) {
  $chosen_methods = array( 'flat_rate' );
   foreach ( $available_methods as $key => $method ) {
     if ( ! in_array( $key, $chosen_methods ) ) {
      unset( $available_methods[$key] );
     }
   }
return $available_methods;
}
add_filter( 'woocommerce_available_shipping_methods', 'custom_hide_shipping_methods', 10, 1 );

This code will hide all shipping methods except for Flat Rate shipping.

If you want to hide all shipping methods and only show the “Local Pickup” method, you can use this code:

function custom_hide_all_shipping_methods( $available_methods ) {
  $chosen_method = array( 'local_pickup' ); // Here's how you can add more than one method: array( 'local_pickup', ' another shipping method ID' );
   foreach ( $available_methods as $key => $method ) {
    if ( ! in_array( $key, $chosen_method ) ) { // This condition checks if the chosen method is not in the available methods, and if it isn't, it removes it from the array. So basically it shows only the chosen method
     unset( $available_methods[$key] );
    }
   }
return $available_methods; // Always remember to return something at the end of your function. In this case we're returning the modified (or unmodified) array of available methods. Without this line your code won't work. It's that simple!;)
}add_filter( 'woocommerce__available Shipping Methods','custom__hide All Shipping Methods', 10, 1 ); // This is where we hook into WooCommerce and specify our function name which is custom__hide all shipping methods.

The 10 specifies the priority and 1 says how many arguments our function accepts. In most cases leave these at their default values unless you have a specific reason to change them.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.