0

I want to hide a shipping method based on customer region and product attribute (deliver_today - Yes/No product attribute).

If the Customer Shipping Region is a certain region and all the cart items have deliver_today attribute Yes then display all the Shipping Methods, but if the Customer Shipping Region is a certain region but not all the cart items have deliver_today attribute Yes then display all the shipping methods except the flatrate_flatrate.

Below is my available.phtml and I added the necessary if else combinations but not working. Can anyone help?

<?php $_shippingRateGroups = $this->getShippingRates(); ?>
<?php $customerRegion = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getRegion(); ?>
<?php if (!$_shippingRateGroups): ?>
    <p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else: ?>

    <?php 
        $customerRegion = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getRegion();
        $cart = Mage::getModel('checkout/cart')->getQuote();
        $deliverToday = true;
        $productModel = Mage::getModel('catalog/product');
        $cart = Mage::getModel('checkout/cart')->getQuote();
        foreach ($cartItems as $item) {
            $product = $productModel->load($item->getProduct()->getId());
            if($product->getData('deliver_today')){
                $deliverToday = false;
            }else{
                $deliverToday = true;
                break;
            }
        }
    ?>

    <dl class="sp-methods">
    <?php $shippingCodePrice = array(); ?>
    <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
        <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
        <dd>
            <ul class="designota-carriers">
            <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
                <?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
                <?php
    if($customerRegion == 'Sample Customer Region'){
        if($_rate->getCode() == 'flatrate_flatrate' && $deliverToday == false) {
                $deliverToday = ' no-display';
        } else if ($_rate->getCode() == 'flatrate_flatrate' && $deliverToday == true){
                $deliverToday = '';
        } else {
                $deliverToday = '';
        }
    } else {
        $deliverToday = ' no-display';
    }
                ?>
    <li class="s_method_<?php echo $_rate->getCode() ?><?php echo $deliverToday; ?>">
       <?php if ($_rate->getErrorMessage()): ?>
        <ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
       <?php else: ?>
            <?php if ($_sole) : ?>
            <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
            <?php else: ?>
            <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>

            <?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
            <script type="text/javascript">
                //<![CDATA[
                    lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
                //]]>
            </script>
            <?php endif; ?>

            <?php endif; ?>
            <label for="s_method_<?php echo $_rate->getCode() ?>">
            <span class="designota-carrier-logos s_method_<?php echo $_rate->getCode() ?>"></span>
            <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
            <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
            <?php echo $_excl; ?>
            <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
            <?php endif; ?>
            </label>
       <?php endif ?>
    </li>
            <?php //} ?>
            <?php endforeach; ?>
            </ul>
        </dd>
    <?php endforeach; ?>
    </dl>
0

Did you try free version of Owebia Shipping? It let you add many conditions to shipping methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.