Free Shipping Unless Weight is greater than 1kg

John asks;
I've hunted high and low and can't find a solution to this problem. I want to provide free shipping for orders over £20 ... but needs to apply a charge if the total weight exceeds 1kg. Is there a way to do this - or a contribution that can be used to do this.
The simplest way to do this is to enable the shipping order_total module to over-ride all of your shipping modules if the amount of the order is greater than £20. This is easy, follow this previous blog post of mine.
However, you also need to disable this if the weight of the order exceeds 1kg. Easy!
Open up checkout_shipping.php and add this code:
-
if ($total_weight> 1) $free_shipping = false;
Right underneath this existing code:
-
$free_shipping = false;
-
if ( ($pass == true) && ($order->info['total']>= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
-
$free_shipping = true;
-
-
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
-
}
-
} else {
-
$free_shipping = false;
-
}
That is it!
Deconstructing the new code
-
if ($total_weight> 1)
$total_weight is a variable that is set to the weight of the cart contents. This is set up at line 61 of the standard checkout_shipping.php file;
-
$total_weight = $cart->show_weight();
We are simply asking if $total_weight is greater than 1. 1 in this case being 1kg. If this is true, then:
-
$free_shipping = false;
Completely obvious - set the $free_shipping to false! This is then used later on in the same file to determine whether or not the order_total module should over-ride your installed shipping modules (or not).
Easy as 123. If you can avoid using a contribution to do something, it is always preferable to do so. After all, the addition of this one line of code;
-
if ($total_weight> 1) $free_shipping = false;
is surely simpler than finding and installing a contribution, and is surely simpler than amending all your installed shipping modules.




