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:
[php]if ($total_weight > 1) $free_shipping = false;[/php]
Right underneath this existing code:
[php]$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;
}[/php]
That is it!
Deconstructing the new code
[php]if ($total_weight > 1)[/php]
$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;
[php]$total_weight = $cart->show_weight();[/php]
We are simply asking if $total_weight is greater than 1. 1 in this case being 1kg. If this is true, then:
[php]$free_shipping = false;[/php]
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;
[php]if ($total_weight > 1) $free_shipping = false;[/php]
is surely simpler than finding and installing a contribution, and is surely simpler than amending all your installed shipping modules.
I’ve done this and in checkout_shipping.php it correctly calculates the shipping costs because the order is above (in my case) 30kg. But when you get to checkout_shipping.php, it still states Free Shipping in the order total! How do I fix this?
You need to have followed this post:
http://www.clubosc.com/free-shipping-in-oscommerce.html
and the changes here:
http://www.clubosc.com/free-shipping-unless-weight-is-greater-than-1kg.html