I'm trying to restrict a shipping method in afterCollectRates
based on a custom product attribute (which I'm injecting with the help of catalog_attributes.xml
public function afterCollectRates(Tablerate $tablerate, $result)
{
$items = $this->checkoutSession->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
if ($item->getProduct()->getMyAttribute()) {
return false;
}
}
return $result;
}
This hides the shipping method if there's a product with the attribute in cart. However, I need the exact opposite. I need to hide the shipping method if no product in cart does have the attribute.
Obviously the cart can have products with and without the attribute, so I can not simply do !$item->getProduct()->getBulkgood()
since the function only accepts return: false;
Any way to make this work?