woocommerce shipping
-
Hi I want to delete flat_rate when free shipping is available. I tried twwo days every code that I could find in internet.But not working. for example these codes
https://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/Just this code works, but it disable all the others. Iwant just flat rate disabled. What should I change? Please.
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
* @return array of modified rates
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( ‘free_shipping’ === $rate->method_id ) {
$new_rates[ $rate_id ] = $rate;
break;
}
}// To unset all methods except for free_shipping, do the following:
if ( ! empty( $new_rates ) ) {
return $new_rates;
}return $rates;
}add_filter( ‘woocommerce_package_rates’, ‘hide_shipping_when_free_is_available’, 10, 2 );
- The topic ‘woocommerce shipping’ is closed to new replies.