Modules in osCommerce – making them interactive
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:
-
$this->enabled = false;
And we can get the value of the purchase via this code:
-
$cart->total
So, putting those together, we need to do this:
-
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:
-
$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):
-
global $order;
to this:
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.



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