Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Created February 26, 2024 19:09
Show Gist options
  • Save rwkyyy/138699e2afcd282f4bb865e7171c9dc4 to your computer and use it in GitHub Desktop.
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ă)
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