Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Last active November 6, 2017 08:34
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 cubehrends/9f23e15fb84a1230cdeea83e15030711 to your computer and use it in GitHub Desktop.
Save cubehrends/9f23e15fb84a1230cdeea83e15030711 to your computer and use it in GitHub Desktop.
WooCommerce Exclude Free Shipping
<?php
function free_shipping_based_on_cart_shipping_class( $is_available ) {
$cart_items = WC()->cart->get_cart();
foreach ( $cart_items as $cart_item ) {
$product = $cart_item['data'];
$class = $product->get_shipping_class();
// start slugs of shipping classes excluded from free shipping with 'bulk'
if ( substr($class, 0, 4) === 'bulk' ) {
return false;
}
}
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'free_shipping_based_on_cart_shipping_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment