Created
February 26, 2024 19:09
-
-
Save rwkyyy/138699e2afcd282f4bb865e7171c9dc4 to your computer and use it in GitHub Desktop.
ascunde alte metode când e transport gratuit + lasă sameday (și ridicare locală)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hide_shipping_when_free_is_available( $rates, $package ) { | |
$new_rates = array(); | |
$free_shipping_available = false; | |
foreach ( $rates as $rate_id => $rate ) { | |
if ( 'free_shipping' === $rate->method_id ) { | |
$new_rates[ $rate_id ] = $rate; | |
$free_shipping_available = true; | |
} | |
} | |
if ( $free_shipping_available ) { | |
foreach ( $rates as $rate_id => $rate ) { | |
if ('samedaycourier' === $rate->method_id || 'local_pickup' === $rate->method_id) { | |
$new_rates[ $rate_id ] = $rate; | |
} | |
} | |
} | |
if ( ! empty( $new_rates ) ) { | |
return $new_rates; | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment