Free Shipping Coupon Codes with Multiple Shipping Rules
I have successfully implemented a coupon code form on the cart page that compares the entered code with the database. I have created a simple discount rule in the cart for a family discount which works fine. My dilemma now is that I would like to have a code in the database for free shipping. I have 4 separate flat rate shipping rules so when the cart subtotal is above a certain number the shipping rate changes. My thought was that I could create a discount rule for free shipping by having the session variable conditions met and have the discount be equal to the shipping amount variable.
Here is my code:
//eCart Rule
function WAEC_iembroider_FreeShipping() {
$totalDiscount = 0;
if (true && ((sizeof($this->Items) > 0) && (isset($_SESSION['CouponCode'])) && ((isset($_SESSION['CouponCode'])?$_SESSION['CouponCode']:"") == "freeship523"))) {
$totalDiscount += $totalShipping;//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
This rule works properly when I have a flat rate discount or a percentage discount from the database, but I am unable to get the $totalShipping to work as the discount. Because there are multiple shipping rules I need the discount amount to change depending on the cart subtotal that is why I tried the $totalShipping.
Any thoughts would be appreciated. I know I could have four separate discount rules for free shipping, but that seems inefficient.