Magento Shipping Method Modifications

After making various conversion rate tweaks on the standard shipping method configurations I thought i’d put it all together in a post for others to use.

The Goals are:

  • If free shipping is an available option don’t show any other options
  • Auto select the available option – to remove an unnecessary click

(Please note in this example I’m using the IG_FlatShipping5 extension – but it works on the standard install too)

Find your available.phtml file in: app/design/frontend/default/default/template/checkout/onepage/shipping_method/or if using the IG_FlatShipping5 extension in: app/design/frontend/default/default/template/ig_flatshipping5

These are the code snippets to add:

<?php
// Remove any other shipping methods if free shipping is available
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
unset($_shippingRateGroups["flatrate"]);
}
?>

 

<?php /*?>Auto Select mod<?php */?>

<?php if ($_rate->getCode()=='freeshipping_freeshipping' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate_flatrate' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate2_flatrate2' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate3_flatrate3' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate4_flatrate4' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate5_flatrate5' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

Obviously if you only using a couple of the flatrates delete the unnecessary ones. Here is the finished patched file:

<?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
<strong><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></strong>
<?php else: ?>
<dl class="shipment-methods">

<?php
// Remove any other shipping methods if free shipping is available
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
unset($_shippingRateGroups["flatrate"]);
}
?>

<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dt><?php echo $this->getCarrierName($code) ?></dt>
<dd>
<ul>
<?php foreach ($_rates as $_rate): ?>

<?php /*?>Auto Select mod<?php */?>

<?php if ($_rate->getCode()=='freeshipping_freeshipping' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate_flatrate' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate2_flatrate2' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate3_flatrate3' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate4_flatrate4' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<?php if ($_rate->getCode()=='flatrate5_flatrate5' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>

<li>
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?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"' ?>/>
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $_rate->getMethodTitle() ?>
<strong>
<?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; ?>
</strong>
</label>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
<?php if ($infoText = $this->getInfoText($code)) { ?>
<div class="shipment-info">
<?php echo $infoText ?>
</div>
<?php } ?>
</dd>
<?php endforeach; ?>
</dl>
<?php endif; ?>

So as an overview, the above modification when using the flat rate 5 extension with free shipping enabled will auto select the options and if free shipping is activated it will remove the unnecessary options.

2 comments
  1. Perfect solution! This is exactly what I was looking for!
    Thank you, thank you thank you for your post!

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

Magento – How to move layered navigation to the top of the sidebar

Next Post

Magento Dashboard Graphs not Showing

Related Posts