Skip to content

Instantly share code, notes, and snippets.

@rayflores
Created September 11, 2014 18:03
Show Gist options
  • Save rayflores/0d3d0d7518b425df7324 to your computer and use it in GitHub Desktop.
Save rayflores/0d3d0d7518b425df7324 to your computer and use it in GitHub Desktop.
<?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