Snippet to skip particular product from shipping rate calculation, if the cart contains multiple shipping classes of given array. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/ and ELEX Shipping Plugins https://elextensions.com/product-category/shipping/
add_filter('wf_shipping_skip_product','skip_my_products',10,3); | |
function skip_my_products($skip = false, $product, $package){ | |
$shipping_class_goup = array('class-a','class-b'); // if these shipping classes coming together in the cart | |
$shipping_class_skip = 'class-a'; // If multiple shipping class of above in the cart, skip this product. | |
$shipping_class = array(); | |
foreach ($package as $key => $item) { | |
$shipping_class[] = $item['data']->get_shipping_class(); | |
} | |
if( $product['data']->get_shipping_class()==$shipping_class_skip && ( count( array_intersect( $shipping_class, $shipping_class_goup ) > 1 ) ) ){ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment