Last active
March 11, 2020 06:28
-
-
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/
This file contains 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
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