How to Hide Cart Subtotal Row In WooCommerce if Free Shipping is set

Question

Above a certain value the customer gets free delivery. In this case, the other delivery cost options are hidden with the following code. However, the subtotal row in the cart and checkout is also redundant, any idea how to hide it?

enter image description here

// Hide ALL shipping rates in ALL zones when Free Shipping is available
add_filter( 'woocommerce_package_rates', 'bbloomer_unset_shipping_when_free_is_available_all_zones', 10, 2 );  
function bbloomer_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;
    } 
 
}
0
eva last 1 month 0 Answers 8 views 0

Leave an answer