I followed this tutorial to add some new shipping methods to my website
http://www.smashingmagazine.com/2014/01/15/create-custom-shipping-methods-magento/#more-130404
However i now need to disable these methods if an If statement is true. I already have the if statement which unsets the free shipping so i know that works. however i do seem to be able to unset the custom shipping methods. I know it is a long shot but does anyone know how i would go about this??
This is the IF statement i am using to unset free shipping if that helps
<?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<?php $quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item)
{
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
if($product->getData('direct_delivery_product')==1){?>
<div class="direct_message">
<?php echo 'You have direct delivery products in your shopping cart. This means it may take longer than the standard 2-5 working days to deliver.';?></div>
<?php unset($_shippingRateGroups["freeshipping"]);
break;
}
}
?>
New collectRate method
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
//return nothing if the shipping method is disabled from config
if (!$this->getConfigFlag('active')) {
return false;
}
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
if($product->getData('direct_delivery_product')==0){
return false;
}
$result = Mage::getModel('shipping/rate_result');
/* @var $result Mage_Shipping_Model_Rate_Result */
$result->append($this->_getStandardShippingRate());
$result->append($this->_getExpressShippingRate());
return $result;
}
Thank you if you can help.