Make shipping option default

Permalink 1 user found helpful
Hi,

I have shipping options on my ecommerce cart. The options are all unselected radio buttons. If a user doesnt select one, they are not charged. I need to make the first option selected by default.

This is the part im looking at:

<?php echo $form->radio('shippingMethodID', $sm->getID(), $o->getOrderShippingMethodID())?>
<?php echo $sm->getName()?> <?php if ($sm->getPrice() > 0) { print t('(Cost: <strong>%s</strong>)', $sm->getDisplayPrice()); } else { print t('(Cost: <strong>Free</strong>)'); } ?>

many thanks

atlantisdigital
 
Mainio replied on at Permalink Best Answer Reply
Mainio
Hi,

At least when I've used eCommerce, it tells me an error if I don't choose a shipping option "You must specify a shipping method.".

However, if you want the first option to be selected by default, I think that can be accomplished by overriding the element template you also took the code from (elements/checkout/shipping/method.php).

The thing you need to do is here.

Change this:
<?php echo $form->radio('shippingMethodID', $sm->getID(), $o->getOrderShippingMethodID())?>


To this:
<?php echo $form->radio('shippingMethodID', $sm->getID(), $o->getOrderShippingMethodID() > 0 ? $o->getOrderShippingMethodID() : (isset($typeID) ? null : $sm->getID()))?>


This should select the first one in the list automatically if your order does not have a shipping method defined yet.

Br,
Antti / Mainio
atlantisdigital replied on at Permalink Reply
atlantisdigital
Hi

thank you very much, this is just what i needed.