Modules in osCommerce – making them interactive

Sometimes you might want to show a Payment or Shipping Module based on other factors. A few examples;

  • Only show Paypal payment method if USPS shipping is chosen.
  • Only show Flat Rate Shipping if number of items in cart is less than three
  • Only show USPS if the total purchase value exceeds $500

I’m sure you get the idea. So, all you need to do is put in an “if” statement, and if the “if” statement is true (or false) – depends upon what you need – turn the shipping or payment module on or off appropriately.

Let’s look at Only show Flat Rate Shipping if purchase value is $200 or more

We know that Flat Rate Shipping is controlled by the shipping module:
/includes/modules/shipping/flat.php so open this ready for a code addition.

Looking at this file, we can plainly see that we can stop the module from working by using this code:

[php]$this->enabled = false;[/php]

And we can get the value of the purchase via this code:

[php]$cart->total[/php]

So, putting those together, we need to do this:

[php]if($cart->total < 200) $this->enabled = false;[/php]

IF purchase value is $200 or less, don’t give a shipping quote! Easy as 123. Add that line of code right underneath:

[php]$this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == ‘True’) ? true : false);[/php]

We need to make one more change. We need to access the cart on a global level, so change this line of code (approx line 18):

[php]global $order;[/php]

to this:

[php]global $order, $cart;[/php]

Now go to your Admin section and activate the Flat Rate module. It will only give a quote if the customer has $200 or more in their cart.

5 Replies to “Modules in osCommerce – making them interactive”

  1. This is great, I’ve got it working a treat! Although, I need it to also work for weight instead of cost. I’ve tried a few variations of your code but a helping hand would be nice!

    Thanks

  2. Hope it is not a problem to bring up this old thread – but could I use

    ($order->info[‘subtotal’]) instead of ($cart->total) ?

    Thanks, Eddy

  3. Gary

    I’m a novice but can handle the simple tasks with no problem. I tried this on the Regions shipping module with no sucess.

    Any help would be greatly appreciated.

    Thanls,

    Bill

Leave a Reply

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