Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Views: 2,304

Results 1 to 10 of 10
7 Feb 2018, 12:01 AM
#1
podgeminster avatar

podgeminster

New Zenner

Join Date:
Mar 2011
Posts:
46
Plugin Contributions:
0

Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Hi,

I have two shipping modules enabled - the Flat Rate module and the Free Shipping Options module.

The Flat Rate module is set up to charge £4.14 for shipping on all orders.

The Free Shipping Options module is set up to offer free shipping for orders totalling £100 or more.

If you place items in the cart and the total is less than £100, only the Flat Rate shipping of £4.15 is displayed as a choice to the shopper.

However, if you place items in the cart and the total is more than £100, both the Flat Rate shipping option and the Free Shipping option is displayed as a choice to the customer.

Is there a way to switch off the Flat Rate shipping option when the order value is high enough to activate the Free Shipping Options module?

It’s a minor issue but I think it’s a little confusing to ask a customer with an order value of £100 and above, “Would you like to pay for shipping or not?”

7 Feb 2018, 12:09 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

What's your sort order for the two shipping methods?

If the flat rate is displayed lower in the list by sort order, then in the flat rate module, it can inspect available data to determine if the freeoptions module is enabled. Then, if it is, to disable the flat rate module.

Otherwise, may have to perform the same analysis as the freeoptions module does, but disable the current module if the conditions are met (opposite of what the freeoptions module does).

7 Feb 2018, 11:05 AM
#3
podgeminster avatar

podgeminster

New Zenner

Join Date:
Mar 2011
Posts:
46
Plugin Contributions:
0

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

To minimise confusion to the customer, I have set the sort order so the Free Shipping option is displayed above / before the Flat Rate option. This way the free option is the first shipping option the customer can see and is selected by default.

Reversing the sort order only reverses the order in which the shipping options are displayed – both options remain with the only difference being that the Flat Rate option is displayed above / before the Free Shipping option.

7 Feb 2018, 1:21 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Podgeminster:

To minimise confusion to the customer, I have set the sort order so the Free Shipping option is displayed above / before the Flat Rate option. This way the free option is the first shipping option the customer can see and is selected by default.

Reversing the sort order only reverses the order in which the shipping options are displayed – both options remain with the only difference being that the Flat Rate option is displayed above / before the Free Shipping option.

So, the sort order will not by itself cause the change that is sought, additional coding is necessary for it all to fit together.

So, if you have your sort order as first described above (with recommendation that no sort order be set to 0) where the freeoptions module has a lower sort order number than the flat rate module, then modify the flat rate module from:

    function __construct() {
      global $order, $db;

      $this->code = 'flat';
      $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' 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) {
          $this->enabled = false;
        }
      }
    }

to:

    function __construct() {
      global $order, $db;

      $this->code = 'flat';
      $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
      }

      if (IS_ADMIN_FLAG !== true  && $this->enabled == true && isset($GLOBALS['freeoptions']) &&  $GLOBALS['freeoptions']->enabled) {
        $this->enabled = false;
      }

       if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' 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) {
          $this->enabled = false;
        }
      }
    }

The above code could allows the module to remain accessible if using some form of admin tool that evaluates the code, but on the catalog side, provided that the freeoptions shipping module has a lower sort order than the flat rate module, the flat rate module will be disabled if the freeoptions module is being presented to the customer.

7 Feb 2018, 7:56 PM
#5
podgeminster avatar

podgeminster

New Zenner

Join Date:
Mar 2011
Posts:
46
Plugin Contributions:
0

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Tried this mod – works perfectly for orders of £100 and over which qualify for free shipping – deactivates the flat rate option when the free option is available.

However, if the total order value is below £100 and qualifies for the Flat Rate shipping of £4.15 only, neither the free or flat rate options are displayed on the Delivery Information page but the message* “Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements.”* is shown.

7 Feb 2018, 8:10 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Arrggh, won't show me the content to edit:

Quote Originally Posted by Podgeminster View Post
Tried this mod – works perfectly for orders of £100 and over which qualify for free shipping – deactivates the flat rate option when the free option is available.

However, if the total order value is below £100 and qualifies for the Flat Rate shipping of £4.15 only, neither the free or flat rate options are displayed on the Delivery Information page but the message “Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements.” is shown.
Sorry, restore includes/modules/shipping/flat.php to the way it was then modify the following:

// class methods
    function quote($method = '') {
      global $order;

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

to:

// class methods
    function quote($method = '') {
      global $order;

      if (IS_ADMIN_FLAG !== true  && $this->enabled == true && isset($GLOBALS['freeoptions']) &&  $GLOBALS['freeoptions']->enabled) {
        $this->enabled = false;
        return false;
      }

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

This is needed because really the module can't be determined to need to be disabled until the other module has had an opportunity to determine a quote. Previous would identify that the module was enabled (as set in the admin basically), but hadn't had an opportunity to determine if a quote should be provided at all from it.

7 Feb 2018, 10:13 PM
#7
podgeminster avatar

podgeminster

New Zenner

Join Date:
Mar 2011
Posts:
46
Plugin Contributions:
0

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

mc12345678:

Arrggh, won't show me the content to edit:

Quote Originally Posted by Podgeminster View Post
Tried this mod – works perfectly for orders of £100 and over which qualify for free shipping – deactivates the flat rate option when the free option is available.

However, if the total order value is below £100 and qualifies for the Flat Rate shipping of £4.15 only, neither the free or flat rate options are displayed on the Delivery Information page but the message “Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements.” is shown.
Sorry, restore includes/modules/shipping/flat.php to the way it was then modify the following:

// class methods
function quote($method = '') {
global $order;

  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                 'cost' => MODULE_SHIPPING_FLAT_COST)));
  if ($this->tax_class > 0) {
    $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }

  if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

  return $this->quotes;
}
> to:
> ```
// class methods
    function quote($method = '') {
      global $order;

      if (IS_ADMIN_FLAG !== true  && $this->enabled == true && isset($GLOBALS['freeoptions']) &&  $GLOBALS['freeoptions']->enabled) {
        $this->enabled = false;
        return false;
      }

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

This is needed because really the module can't be determined to need to be disabled until the other module has had an opportunity to determine a quote. Previous would identify that the module was enabled (as set in the admin basically), but hadn't had an opportunity to determine if a quote should be provided at all from it.

Tried the amended mod - Still getting the message “Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements.” Was showing on Step 1 of 3 – Delivery Information” page but is now showing when you click and proceed to “Step 2 of 3 - Payment Information” page.

8 Feb 2018, 1:21 AM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

mc12345678:

Arrggh, won't show me the content to edit:

Quote Originally Posted by Podgeminster View Post
Tried this mod – works perfectly for orders of £100 and over which qualify for free shipping – deactivates the flat rate option when the free option is available.

However, if the total order value is below £100 and qualifies for the Flat Rate shipping of £4.15 only, neither the free or flat rate options are displayed on the Delivery Information page but the message “Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements.” is shown.
Sorry, restore includes/modules/shipping/flat.php to the way it was then modify the following:

// class methods
function quote($method = '') {
global $order;

  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                 'cost' => MODULE_SHIPPING_FLAT_COST)));
  if ($this->tax_class > 0) {
    $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }

  if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

  return $this->quotes;
}
> to:
> ```
// class methods
    function quote($method = '') {
      global $order;

      if (IS_ADMIN_FLAG !== true  && $this->enabled == true && isset($GLOBALS['freeoptions']) &&  $GLOBALS['freeoptions']->enabled) {
        $this->enabled = false;
        return false;
      }

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

This is needed because really the module can't be determined to need to be disabled until the other module has had an opportunity to determine a quote. Previous would identify that the module was enabled (as set in the admin basically), but hadn't had an opportunity to determine if a quote should be provided at all from it.

Aggrivating as all to figure out, but finally did. Needed one more factor in the new if statement:
Changing the base code of:

// class methods
    function quote($method = '') {
      global $order;

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class,  $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

to:

// class methods
    function quote($method = '') {
      global $order;

      if (IS_ADMIN_FLAG !== true &&  $this->enabled == true && isset($GLOBALS['freeoptions'])  &&  $GLOBALS['freeoptions']->enabled[B] && $method == ''[/B]) {
        $this->enabled = false;
        return false;
      }

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class,  $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

This way when a specific method has been identified to obtain a quote, the module will remain active for processing which is basically what was going on when trying to submit the flat rate method.

Totally tested this and the above worked for all conditions attempted (slightly exceeded the threshold to show freeoptions and flat was disabled, slightly less than the cutoff and of the two only flat showed...

8 Feb 2018, 7:16 PM
#9
podgeminster avatar

podgeminster

New Zenner

Join Date:
Mar 2011
Posts:
46
Plugin Contributions:
0

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

Excellent!

Thoroughly tested (so far as possible) and appears to work perfectly.

Thank you!

27 May 2020, 10:45 PM
#10
jimmie avatar

jimmie

Totally Zenned

Join Date:
Jan 2013
Location:
New Port Richey, Florida
Posts:
969
Plugin Contributions:
0

Re: Deactivate Flat Rate Shipping module when Free Shipping Options module activates?

i applied this to advanced shipper,```
if (IS_ADMIN_FLAG !== true && $this->enabled == true && isset($GLOBALS['freeoptions']) && $GLOBALS['freeoptions']->enabled && $method == '') {
$this->enabled = false;
return false;
}

it does work, but doesnt let the customer choose another shipping method. i can activate fed ex ground and standard overnight as options to the customer  but only the cheapest gets totaled. the standard overnight options shows as checked but cheapest is totaled. if i revert changes or turn off freeoptions than everything works as should.