Last active
          June 5, 2017 21:23 
        
      - 
      
- 
        Save rynaldos-zz/9de09f00765c83868fb7fbd731c3aa1b to your computer and use it in GitHub Desktop. 
    [WooCommerce 3.0] Hide all other shipping methods, but keep free shipping / local pickup plus
  
        
  
    
      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
    
  
  
    
  | 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 plus 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 ); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment