Created
April 22, 2022 08:22
-
-
Save bradleysa/d49394dc5c450fe76e376d1a94ec28da to your computer and use it in GitHub Desktop.
WC: Show Free Shipping and Local Pickup Plus
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
/** | |
* Hide shipping rates when free shipping is available, but keep "Local Pickup Plus" | |
* 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_plus' === $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 ); | |
/** When Free Shipping is available, hide USPS, but still offer Local Pickup. Snippet works with Local Pickup Plus | |
https://docs.woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/#section-5 | |
NOTE: I changed Line 19 to add "_plus" | |
FROM: if ('local_pickup' === $rate->method_id ) { | |
TO: if ('local_pickup_plus' === $rate->method_id ) { | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment