I’m new and looking for help.
I want to hide delivery methods in my cart that do not have a price listed.
function ts_hide_shipping_without_prices( $rates ) {
foreach ( $rates as $rate_id => $rate ) {
// Check if the cost is zero and the method is not free
if ( 0 == $rate->cost && 'free_shipping' !== $rate->method_id ) {
unset( $rates[ $rate_id ] );
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'ts_hide_shipping_without_prices', 100 );
I have the code below, but it also hides Free Shipping because it also has no price. I don’t want it!
I want the code below to bypass Free Shipping. Free shipping is supposed to be displayed always.
New contributor
Mateusz Kulesza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.