View Single Post
  #12  
Old 01-22-2004, 02:13 PM
 
spingary spingary is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 51
 

Default TINY mod to do Free Shipping for orders over $X w/real time

I also needed to do a "Free Shipping for orders over $X" while keeping the other real-time methods working, and without using flat rates. I've come up with a method that only requires adding ONE line to X_cart's php files. If anyone's seen any of my other posts, I really hate hacking at the x_cart code due to upgrade issues, so I made this as painless as possible.

The method is to add our own real-time shipping method.

First, let's add our new shipping method into the database table xcart_shipping. I call it "Free Shipping - Orders Over $200". The code I use is "FREEOVERX", subcode "201" - an arbitrary number I pick that is far enough away from the predefined X_Cart shipping methods. I don't set a weight limit, but you might want to do that just in case:

Code:
INSERT INTO xcart_shipping VALUES (103, 'Free Shipping - Orders Over $200', '', 'L', 'FREEOVERX', '201', 5, 'Y', '', '0.00', 0);

Now, here is the only hack needed -- in shipping/myshipper.php:

Code:
After this line: include "../shipping/mod_DHL.php"; Add this line: include "../shipping/mod_CUSTOM.php";

"mod_CUSTOM.php" is where I put my custom shipping methods. Right now, I only have one, the "Free Shipping Over $X". Here's the code for mod_CUSTOM.php:

Code:
<? // Edit the amount valid for free shipping here: $freeOverAmount=200; if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); } global $product; // Make sure this shipping method is available foreach ($allowed_shipping_methods as $key=>$value) if ($value["code"] == "FREEOVERX") $FREEOVERX_FOUND = true; if ($FREEOVERX_FOUND) { $row = func_query_first("SELECT shippingid, subcode FROM $sql_tbl[shipping] WHERE code='FREEOVERX' AND active='Y'"); if ($row && ($product["subtotal"] >= $freeOverAmount)) { $rate = 0; $intershipper_rates[] = array("methodid" => $row['subcode'], "rate" => $rate); } } ?>

As you can see, you can pretty much do anything you want in this code to calculate shipping rates.

Let me know if you have trouble getting it to work. Have fun!

Oh, I forgot to mention, I am using version 3.5.2.
Reply With Quote