How Much To Spend For Free Shipping

By | February 13, 2009

On the osCommerce Forum, Jim asks;

I notice that oscommerce has the default ability to have all orders over a certain amount to qualify for free shipping. Is there a contribution that would add text to the effect of

“You are only [X amount of money] away from qualifying for free shipping.”

With the amount of money being based on the cart contents of the time. It would be a nice device to have to push up the average order amount, anyone know of such a contribution?

There probably is a contribution, but by the time you’ve found it, and checked to make sure the code is OK, it’s quicker to simply come up with some code that does the same thing.

Step 1. make the language definitions

Open up includes/languages/english.php and add the following lines of code directly before the end ?> in the file

[php]define(‘SHIPPING_CHARGE’, ‘Only another %s until you qualify for free shipping.’);
define(‘SHIPPING_FREE’, ‘You qualified for FREE shipping!’);[/php]

These lines have to be in the english.php as one or the other of these will show in ALL osCommerce pages in your store. Did you notice the %s rather than the actual price? We’re going to do something special with that, read on 🙂

Step 2: Amend the Shopping Cart infoBox

In this file we are going to paste code which shows one or other of the language definitions based upon the value of the cart contents!

So, open up /includes/boxes/shopping_cart.php and paste the following code directly before this line of code <!– shopping_cart_eof //–>


show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ? sprintf(SHIPPING_CHARGE, tep_output_string_protected($currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER – $cart->show_total()))) : SHIPPING_FREE; ?>


Save both files and upload. Voila. Easy as 123.

Deconstructing the PHP

1. We know that the value of the cart contents is assigned to $cart->show_total()
2. We know that the value of the free shipping in the order_total module is assigned to MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER

So this piece of code: $cart->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER compares the two. Depending upon which is true (which is greater than the other), this piece of code: sprintf(SHIPPING_CHARGE, tep_output_string_protected($currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER – $cart->show_total()))) : SHIPPING_FREE; shows either the SHIPPING_CHARGE language, or the SHIPPING_FREE language.

How about that %s ?

Well, that is used by the sprintf() function to format data that is passed to it. You can see that part of our code looks like this: sprintf(SHIPPING_CHARGE, tep_output_string_protected($currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER – $cart->show_total()))) – the 2nd part of this code is the value %s (in other words the total of the free shipping amount LESS the cart total). Make sense?

Images, images, images

When the value of the cart is LESS than the Free Ship Amount;

And when the value of the cart is equal to or greater than the Free Ship Amount;

Easy as 123!

7 thoughts on “How Much To Spend For Free Shipping

  1. Tomee

    Super cool, and thank you, I was looking for something like this a few days ago when we enabled free shipping in our shop.

  2. Trent

    Is there any way to get this working inside header.php (I have a mini-cart up the top of my site) on 2.3.1? Thanks

  3. Gary Post author

    Trent – instructions would be no different for 2.3.1

  4. Trent

    Hi Gary. Not sure what I was doing wrong before, but I gave it another go and sure enough, it works perfect 🙂 Also added it to the actual shopping cart next to the checkout button.


  5. rub

    Hi Gary,

    Can you please advice where to add it in OScommerce 2.3.1 shopping cart?

    Thank you!

  6. Gary Post author

    You can add it anywhere. Try right after the line which includes;

    echo $currencies->format($cart->show_total());

Leave a Reply

Your email address will not be published.