Zen Cart Add Shipping Weight to Always Free Shipping Items for Certain Zones

In zen cart, products marked as “Always Free Shipping” are free shipping for everyone, regardless of the Zone set on the FREE SHIPPING! freeshipper module unless you add custom php code to manage which zones get free shipping. Say, for example, that you have a zone for the lower 48 states. Someone from Alaska purchases a “Always Free Shipping” item. At checkout the item will have a weight of 0 so the shipping amount will be $0 or very low depending on your shipping settings. This Easy Help Zen Cart Tutorial will show you how to add some custom php code that will allow you have the “Always Free Shipping” items set as free shipping to just one zone with anyone outside of the zone seeing regular calculated shipping prices.

In your favorite plain text editor open the includes/classes/shipping.php file. This is a zen cart core file so be sure to back it up and make a note that you have changed this file for future upgrades.

Find this:


function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

Immediately after, add this:


// bof: allow 1 zone only for Always Free Shipping
// add zone to FREE SHIPPING! freeshipper
    global $db, $order, $cart;
        $valid_zone_id = 21;
        $check_flag = false;
http://www.zen-cart.com/showthread.php?214171-Shipping-Weight-on-Free-Shipping-Items

        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $valid_zone_id . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        if ($check_flag == false) {
          $total_weight += $_SESSION['cart']->free_shipping_weight;
        }
// bof: allow 1 zone only for Always Free Shipping

So you have this:


  function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

// bof: allow 1 zone only for Always Free Shipping
// add zone to FREE SHIPPING! freeshipper
    global $db, $order, $cart;
        MODULE_SHIPPING_FREESHIPPER_ZONE;
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $valid_zone_id . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        if ($check_flag == false) {
          $total_weight += $_SESSION['cart']->free_shipping_weight;
        }
// bof: allow 1 zone only for Always Free Shipping

    $this->abort_legacy_calculations = FALSE;
    $this->notify('NOTIFY_SHIPPING_MODULE_PRE_CALCULATE_BOXES_AND_TARE');
    if ($this->abort_legacy_calculations) return;

For UPS shipping, edit the file includes/modules/shipping/ups.php.

Find this:


 if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
    }

Change it to this:


Code:
    // disable only when entire cart is free shipping
// bof: disabled for Always Free Shipping 1 zone to always show additional methods
//    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
//    }
// eof: disabled for Always Free Shipping 1 zone to always show additional methods

If you need help with your zen cart web site please contact us for a quote.

Picaflor Azul specializes in responsive zen cart design. Contact us to convert your current zen cart to a responsive design, or to have a fantastic new custom design made just for your business.

zen cart plus picaflor azul equals success

Leave a Reply