Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[General Snippets][Hide other shipping methods, but keep "Local pickup" when “Free Shipping” is available]
/**
* 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 );
@bmtamim

This comment has been minimized.

Copy link

@bmtamim bmtamim commented Oct 25, 2020

How Can I show 2diffrent "local pickup" When free shipping is available Like I have 2 local pickup shipping method,

  1. First One is "Local Pickup"
  2. Second one is "Order In Table",

So, How can I show both of them when Free shipping is available.
Note: Both are Local pickup

Screenshot_383

@kodamilla

This comment has been minimized.

Copy link

@kodamilla kodamilla commented Mar 8, 2021

How Can I show 2diffrent "local pickup" When free shipping is available Like I have 2 local pickup shipping method,

  1. First One is "Local Pickup"
  2. Second one is "Order In Table",

So, How can I show both of them when Free shipping is available.
Note: Both are Local pickup

Screenshot_383

Same problem here. Dont show more than 1 local pickup.

@philmorley

This comment has been minimized.

Copy link

@philmorley philmorley commented Mar 10, 2021

How Can I show 2diffrent "local pickup" When free shipping is available Like I have 2 local pickup shipping method,

  1. First One is "Local Pickup"
  2. Second one is "Order In Table",

So, How can I show both of them when Free shipping is available.
Note: Both are Local pickup

Same problem here. Dont show more than 1 local pickup.

Remove break; from line 21

@WebStarLink

This comment has been minimized.

Copy link

@WebStarLink WebStarLink commented May 27, 2021

Okay. it works. But how can I sort free shipping under local pickup?

I mean when free shipping unavailable, my list looks like:
Local
Post 5$
Courier 10$

When free shipping available my list looks like:
Free shipping
Local

I want to shos as:
Local
Free shipping.

Thank for reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment