Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Last active December 5, 2022 09:30
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/ceee97c9a7bda22ffe1dc80cca262114 to your computer and use it in GitHub Desktop.
Save cubehrends/ceee97c9a7bda22ffe1dc80cca262114 to your computer and use it in GitHub Desktop.
WooCommerce Hide Shipping when Pickup Required
<?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