View Single Post
  #1  
Old 08-25-2004, 03:33 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default FREE SHIPPING mod based on order total.

Here's a quick and easy mod to let you give free shipping based on an order subtotal. First you'll need to add a variable to the xcart_config table of your xcart database. Using something like PHPMyadmin, take one of the existing Shipping config fields and just duplicate it. Change the values to be:

name: free_shipping_threshold
comment: FREE SHIPPING THRESHOLD
Give free shipping on orders with subtotal greater than this value. Set to 0 to disable
value: 0
category: Shipping
orderby: 4
type: text
defvalue: 0

Save the new row to your database. That will give you a nice config option in your shipping admin menu, so you can easily change the order subtotal required to get free shipping discounts.

Now open your include/func.php file and modify your func_caluculate_single() function. Search for the code that handle the free shipping coupon...
Code:
if (!empty($coupon_type) and $coupon_type == "free_ship") { # # Apply discount coupon 'Free shipping' # if (($single_mode) or ($provider_for == $discount_coupon_data["provider"])) $coupon_discount = $shipping_cost; $shipping_cost = 0; }

and add this bit of code directly below that code
Code:
//added by brett to offer free shipping if the free shipping threshold has been met if ($config["Shipping"]["free_shipping_threshold"] > 0 && $subtotal >= $config["Shipping"]["free_shipping_threshold"]){ //$coupon_discount = $shipping_cost; (commented out..see last post for explanation) $shipping_cost = 0; }

Now to use this mod, just log in as an admin and open your general settings page and select "shipping options" from the pulldown menu. Then find the new value you set up for the free_shipping_threshold and enter a value greater than 0 to activate the module. This will give free shipping for orders that have subtotals greater than the threshold you set. It also sets the customer's discount equal to whatever your shipping cost would have been and displays it the same way a free shipping coupon would be displayed. This has the added benefit that it should save the discount value in your store's order stats, just like all the other discounts (although no coupon code will ever be set). This code is only tested on v3.5.7, but should work with most of the 3.5.x branch. I have no idea what the 4.0 branch looks like, so I can't help anyone with that version yet. Also, i just realized that this code will interfere if a user tries to use a discount coupon. A fix for that would probably be to just change the above code from
Code:
//disregard this part of the code, just comment out these lines //$coupon_discount = $shipping_cost;
to
Code:
//disregard this part of the post...just comment out the $coupon_discount line //$coupon_discount += $shipping_cost;

Since coupons have theoretically been applied already, this will just add the shipping charge to whatever the existing discount value is.

ENJOY!

UPDATE: I have modified the code above by commenting out the $coupon_discount lines because it interfered with the normal coupon discount display in order receipts. Otherwise, the code is fine.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote