//Hide specific Flat Rates when Free Shipping is available add_filter( 'woocommerce_package_rates', 'conditionally_hide_shipping_methods', 100, 2 ); function conditionally_hide_shipping_methods( $rates, $package ) { // HERE yours 2nd flat rate "Express Shipping" (that you never hide) in the array: $flat_rates_pickpack = array( 'wc_pont_shipping_method:3', 'local_pickup:9' ); $free = $flat2 = array(); foreach ( $rates as $rate_key => $rate ) { // Updated Here To if ( in_array( $rate->id, $flat_rates_pickpack ) ) $flat2[ $rate_key ] = $rate; if ( 'free_shipping' === $rate->method_id ) $free[ $rate_key ] = $rate; } return ! empty( $free ) ? array_merge( $free, $flat2 ) : $rates; }
Leave a Reply