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:
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, $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.