Skip to content

Instantly share code, notes, and snippets.

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 PluginHive/da2ec389d120a886a0333cf094eba2d2 to your computer and use it in GitHub Desktop.
Save PluginHive/da2ec389d120a886a0333cf094eba2d2 to your computer and use it in GitHub Desktop.
Code snippet to skip certain WooCommerce products from final packaging. Works only with WooCommerce Shipping Plugins from PluginHive: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
add_filter('wf_shipping_skip_product','skip_my_products',10,3);
function skip_my_products($skip = false, $product, $package){
$shipping_free_classes = array(16); // array of shipping class ids to exclude from cart
$shipping_class = $product['data']->get_shipping_class_id();
if(in_array($shipping_class, $shipping_free_classes)){
$skip = true;
}
return $skip;
}
// In the above code, $shipping_free_classes contains the shipping class IDs which need to be excluded from the cart.
// $shipping_class contains the shipping class IDs of the products which are present in the cart.
// If $shipping_free_classes contains $shipping_class, then assign true to $skip and return it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment