Public Ticket #2718962

Hide other shipping methods when “Free Shipping” is available

Closed
Comments
2 Tickets 2
Gerald started the conversation 6 years ago on March 12, 2021 at 8:08pm

Hi, 

I'm doing try of "Hide other shipping methods when “Free Shipping” is available". I know that this is part of woocommerce core, But the folliwing snippets doesn't work. I have the idea that your plugin in the section "edit group" not permitted this function. Could you confirm this please?

Thank you in advance.

/** * Hide shipping rates when free shipping is available, but keep "Local pickup" * Updated to support WooCommerce 2.6 Shipping Zones */ 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; } } if ( ! empty( $new_rates ) ) { //Save local pickup if it's present. foreach ( $rates as $rate_id => $rate ) { if ('local_pickup' === $rate->method_id ) { $new_rates[ $rate_id ] = $rate; break; } } return $new_rates; } return $rates;} add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );


2,762
KingsPlugins replied 6 years ago on March 14, 2021 at 8:51pm

Hi Gerald,

That snippet should work with our plugin - it has been working for a long time.


I just tested this and here's what an issue might be:

When testing, simply refreshing/reloading the checkout page (e.g. CTRL + R) doesn't seem to actually update the methods. Change the country, and then change it back, to make sure the methods update correctly.


Other than that, it is working fine in my tests. You can also completely disable this functionality of B2BKing by going to B2BKing->Settings->Components->Disable shipping & payment methods control

Or you can deactivate B2BKing completely to see if that affects results in any way.


Kind regards,

Stefan


Sign In