I'm using UPS and FedEx quotes. I would like to offer free shipping for "qualified" products when the total for "qualified products" in the cart exceeds $250. Non-qualified products may also be in the cart and shipping will still apply to those items. (same way Amazon does it)
1. I have a cck field called field_shipping_extra to indicate if the product is "qualified" for free shipping
Value of the field: Null = qualifies, 1=oversized (doesn't qualify)
2. Flat Rate won't work, because if I have a non-qualified product in the cart (regardless of cart total), I need to calculate and charge for its shipping.
3. Examples:
* = qualified
A* = $100
B = $300
Cart 1 = A* x 1 + B x 1 = $400 (cart total doesn't really matter), BUT only $100 for the total of qualified products -> Free shipping doesn't apply
Cart 2 = A* x 3 + B x 1 = $600, WITH $300 total of qualified products -> Shipping is only calculated on B, and A* ships for free.
4. I created a custom module with the following code, piecemeal from several forum topics. I am not a programmer so I have no idea if it's set up correctly, but hopefully at the very least it gives a train of logic on perhaps how to address this case. It currently doesn't return any value - the shipping status bar just runs. Any help, advice, or alternative approach is greatly appreciated!
<?php
function mymodule_uc_nonshippable_cart_item($op, &$item) {
switch ($op) {
case 'load':
$items = uc_cart_get_contents();
if (!empty($items)) {
foreach ($items as $product) {
//Get qualified products and calculate total of qualified products
if ($product->field_shipping_extra[0]['value']!= 1){
$total += ($product->price) * $product->qty;
}
}
}
//Check if qualified total is over 250
if ($total > 250.00) {
foreach ($items as $product) {
if ($product->field_shipping_extra[0]['value']!= 1){
//if a qualified product, set shipping to 0 so it won't calculate
$item->data['shippable'] = "0";
} else {
//if a non-qualified product, still calculate shipping
$item->data['shippable'] = "1";
}
}
}
break;
}
}
?>