0

I need to auto select the cheapest UPS shipping rate on checkout page.

enter image description here

in the picture above I need Ground to be selected by default.

we are trying to make our checkout easier for customers and pre-selecting shipping rate is the first step.

PS: I tried modifying

app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml

and had checked="checked" placed for the first item and it worked. But grandtotal didn't include shipping cost in that case.

2 Answers 2

1

You can fire a JS click method after page load like

<script type="text/javascript">
//<![CDATA[
jQuery(function($) {
    $('input[name="shipping_method"]').get(0).click;
});
//]]>

You can use the same thing on specific element id of Ground

1
  • your answer won't work on cart page in shipping calculator. I want magento to preselect the cheapest option there too. Feb 23, 2017 at 10:21
0

I made it work by these code edits:

  1. copy app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php to app/code/local/Mage/Usa/Model/Shipping/Carrier/Ups.php
  2. edit app/code/local/Mage/Usa/Model/Shipping/Carrier/Ups.php and make collectRates look like this:

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {    
    if (!$this->getConfigFlag($this->_activeFlag)) {
        return false;
    }    
    
    $this->setRequest($request);
    
    $this->_result = $this->_getQuotes();
    $this->_updateFreeMethodQuote($request);
    
    #THIS IS MY CUSTOM CODE: START
    
    try{ 
    $q = Mage::getSingleton('checkout/type_onepage');
    if(!$q->getQuote()->getShippingAddress()->getShippingMethod()){
     if (is_object($this->_result)) {
        foreach($this->_result->getAllRates() as $i=>$item){
            if ($item->getMethod() && $item->getCarrier()){
                $q->getQuote()->getShippingAddress()->setShippingMethod($item->getCarrier().'_'.$item->getMethod());
                break;
            }    
        }    
     }    
    }    
    }catch(Exception $e){}
    
     #THIS IS MY CUSTOM CODE: FINISH
    
    return $this->getResult();
    }    
    

now the cheapest option is preselected on checkout and on cart shipping estimator.

thanks all.

3
  • This ignores any promotional rule applied on shipping rate
    – Garry
    Jun 28, 2017 at 23:48
  • could be but we don't use promotional rules in our case Jun 29, 2017 at 1:31
  • @KonstantinGerasimov In my cart page ESTIMATE SHIPPING AND TAX, UPS display shipping price, but checkout page UPS not showing. How can I solve this issue?
    – zus
    Feb 20, 2018 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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