Created
March 22, 2022 11:52
-
-
Save wpflames/8b7b9f9504818a1d836c895c98f7081e to your computer and use it in GitHub Desktop.
Unset All Shipping Methods if Free Shipping is Available
This file contains hidden or 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
| // ========================================================================= | |
| // Unset Shipping Methods if Free Shipping is Available | |
| // ========================================================================= | |
| function unset_shipping_when_free_is_available_all_zones( $rates, $package ) { | |
| $all_free_rates = array(); | |
| foreach ( $rates as $rate_id => $rate ) { | |
| if ( 'free_shipping' === $rate->method_id ) { | |
| $all_free_rates[ $rate_id ] = $rate; | |
| break; | |
| } | |
| } | |
| if ( empty( $all_free_rates )) { | |
| return $rates; | |
| } else { | |
| return $all_free_rates; | |
| } | |
| } | |
| add_filter( 'woocommerce_package_rates', 'unset_shipping_when_free_is_available_all_zones', 9999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment