Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 11, 2020 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/63cbc9436939dada64972ce78c4b6c72 to your computer and use it in GitHub Desktop.
Save xadapter/63cbc9436939dada64972ce78c4b6c72 to your computer and use it in GitHub Desktop.
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