Created
          September 11, 2014 18:03 
        
      - 
      
- 
        Save rayflores/0d3d0d7518b425df7324 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | <?php | |
| add_filter( 'woocommerce_available_shipping_methods', 'custom_shipping_methods' ); | |
| function custom_shipping_methods( $available_methods ) { | |
| $carrier = 'ups'; | |
| foreach ( WC()->cart->cart_contents AS $item ) { | |
| if ( has_term( 'large-item', 'product_shipping_class', $item['product_id'] ) ) { | |
| $carrier = 'usps'; | |
| continue; | |
| } | |
| } | |
| $states = array( 'AK', 'HI' ); | |
| if ( ! in_array( WC()->customer->get_state(), $states ) ) { | |
| $available_methods = wp_filter_object_list( $available_methods, array( 'method_id' => $carrier ), 'NOT' ); | |
| } | |
| return $available_methods; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment