About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

Follow osc_pro on Twitter

Free Shipping Unless Weight is greater than 1kg

Written By Gary on Mar 25 2009 · Comments (0) Follow osc_pro on Twitter

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:
  1. if ($total_weight> 1) $free_shipping = false;

Right underneath this existing code:

PHP:
  1. $free_shipping = false;
  2.     if ( ($pass == true) && ($order->info['total']>= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
  3.       $free_shipping = true;
  4.  
  5.       include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
  6.     }
  7.   } else {
  8.     $free_shipping = false;
  9.   }

That is it!

Deconstructing the new code

PHP:
  1. 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;

PHP:
  1. $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:

PHP:
  1. $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;

PHP:
  1. 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.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


No Comments

No comments yet.

Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!