If you wish to hide the “Free Shipping” option on your cart page based on the cart subtotal, the following code snippet will help you achieve this objective.
function ts_filter_woocommerce_package_rates( $rates, $package ) { // Get subtotal $subtotal = $package['cart_subtotal']; // Hide free shipping if subtotal > 0 if ( $subtotal > 0 ) { // Loop through rates foreach ( $rates as $rate_id => $rate ) { // Check if it is the free shipping method if ( 'free_shipping' === $rate->method_id ) { // Remove the free shipping method unset( $rates[$rate_id] ); } } } return $rates; } add_filter( 'woocommerce_package_rates', 'ts_filter_woocommerce_package_rates', 10, 2 );
Output
When the cart subtotal is greater than 0 in the WooCommerce cart page, the “Free Shipping” shipping option is hidden.
Moreover, you can also hide WooCommerce shipping methods for certain conditions including to hide free shipping until the order total is greater than $250.