I am trying to hide shipping methods based on the availability of other shipping methods (by their IDs), for a somewhat complex shipping setup.
Based on other code snippets I've found (for other use cases, excluding states or only showing free shipping if available), I came up with this:
function hide_duplicate_shipping_methods ( $rates ) {
foreach ( $rates as $rate_id => $rate ) {
if ( 'flat_rate:10' === $rate->method_id ) {
unset( $rates['flat_rate:28'] );
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_duplicate_shipping_methods', 100 );
However, this doesn't hide anything and I really can't find or think of anything else.
Any advice?