About Club osCommerce

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

StumbleUpon It! DIGG It!

Modules in osCommerce – making them interactive

Written By Gary on Jun 21 2008 · Comments (1)

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!


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:
  1. $this->enabled = false;

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

PHP:
  1. $cart->total

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

PHP:
  1. if($cart->total <200) $this->enabled = false;

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

PHP:
  1. $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);

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

to this:

PHP:
  1. global $order, $cart;

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.

1 Comment

  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

    Comment by Adam — November 13, 2008 @ 1:04 pm


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!