Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Created September 17, 2019 07:35
Show Gist options
  • Save forsvunnet/8783f123343ec5e2d2ab0b015cec86c3 to your computer and use it in GitHub Desktop.
Save forsvunnet/8783f123343ec5e2d2ab0b015cec86c3 to your computer and use it in GitHub Desktop.
Black list shipping classes for bring shipping rates
<?php
/**
* Filter the bring shipping rates.
*/
add_filter('bring_shipping_rates', function( $rates ) {
$shipping_classes = [
'halvpall',
'pall',
'stein',
'uuni-shipping',
];
// Look for items with a shipping class that doesn not allow mail.
$items = WC()->cart->get_cart();
foreach ( $items as $item ) {
$shipping_class = $item['data']->get_shipping_class();
if ( in_array( $shipping_class, $shipping_classes ) ) {
return [];
}
}
return $rates;
}, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment