Created
March 27, 2020 12:19
-
-
Save daveloodts/b81ba5970b7580e21cbcb282ce93d7a4 to your computer and use it in GitHub Desktop.
Hide free shipping in cart when multiple specific shipping class #woocommerce #shipping
This file contains hidden or 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
/* verberg gratis shipping > €85 als verzendklasse groot in winkelwagen zit */ | |
/* source: https://businessbloomer.com/woocommerce-disable-free-shipping-if-cart-has-shipping-class/ */ | |
add_filter( 'woocommerce_package_rates', 'hide_free_shipping_for_shipping_class', 10, 2 ); | |
function hide_free_shipping_for_shipping_class( $rates, $package ) { | |
$shipping_class_target = array( 220,318,319); // shipping class ID (to find it, see screenshot below) | |
$in_cart = false; | |
foreach( WC()->cart->get_cart_contents() as $key => $values ) { | |
$product_shipping_class = $values[ 'data' ]->get_shipping_class_id(); | |
if (in_array($product_shipping_class, $shipping_class_target)) { | |
$in_cart = true; | |
break; | |
} | |
} | |
if( $in_cart ) { | |
unset( $rates['free_shipping:3'] ); // shipping method with ID (to find it, see screenshot below) | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment