How can I check if all the cart items have my custom attribute? And if item/items all have the custom attribute prints a message but if one of the cart item/items doesn't have the custom attribute, it prints an error message in the checkout?
Please try below code
<?php
$productModel = Mage::getModel('catalog/product');
$cart = Mage::getModel('checkout/cart')->getQuote();
$error = "";
foreach ($cart->getAllItems() as $item) {
$product = $productModel->load($item->getProduct()->getId());
if($product->getData('your_attribute_code')){
$message = "your message for items have attribute";
$error = 0;
}else{
$message = "your message for items have no attributes";
$error = 1;
break;
}
}
if($error == 1){
Mage::getSingleton('core/session')->addError($message);
}else{
Mage::getSingleton('core/session')->addSuccess($message);
}
?>