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 //–>
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!