Last active
December 5, 2022 09:30
-
-
Save cubehrends/ceee97c9a7bda22ffe1dc80cca262114 to your computer and use it in GitHub Desktop.
WooCommerce Hide Shipping when Pickup Required
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
<?php | |
function wdt_hide_shipping_when_pickup_required( $rates, $package ) { | |
$class_slug = 'pickup'; | |
// Checking in cart items | |
foreach( WC()->cart->get_cart() as $cart_item ){ | |
// If we find the shipping class | |
if( $cart_item['data']->get_shipping_class() == $class_slug ){ | |
unset($rates['flat_rate:2']); // Remove flat rate | |
unset($rates['free_shipping:3']); // Remove free shipping | |
break; // Stop the loop | |
} | |
} | |
return $rates; | |
} | |
add_filter('woocommerce_package_rates', 'wdt_hide_shipping_when_pickup_required', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment