Forums / Addon Shipping Modules / Free shipping AFTER discount codes?

Free shipping AFTER discount codes?

Views: 10,222

Results 1 to 14 of 14
23 Mar 2014, 3:25 AM
#1
glamourdolleyes avatar

glamourdolleyes

New Zenner

Join Date:
Mar 2009
Posts:
86
Plugin Contributions:
0

Free shipping AFTER discount codes?

I have done lots of googling to see if this is something that can be fixed, found things as early as 2006 and the latest being 2012 but no one ever finds a definite answer. I am guessing nothing has come of this?

I want to have the free shipping applied AFTER a discount code. For example, I offer free shipping worldwide for orders of $40 or more..

Example order:

Sub-Total: $43.50
Free Shipping Options (Free Shipping): $0.00
Discount Coupon: XXXXXXX : $6.53
Shipping Insurance: $2.50
Total: $39.47

This person just got FREE SHIPPING (Internationally as well and that is expensive) and technically only spent $36.97. It shouldn't allow free shipping because the total after a discount code is NOT $40.

Is there a way to fix this, has someone created code (or can create code) for this yet?

23 Mar 2014, 6:55 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping AFTER discount codes?

This was totally NOT fun to do ...

This is what I finally did in Zen Cart v1.5.1 to make this work, after a zillion attempts to get it working right ...

Start with the shipping module, this was a total re-write, then I found a better way so do this:
/includes/modules/shipping/freeoptions.php

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

[B]// bof: manage Free Shipping Options exclude discounts
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && isset($_SESSION['cc_id'])) {
  $this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
[/B]
      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {

Then add the code in RED:

// final check for display of Free Options
      if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

[B]// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
  $this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
[/B]
      if ($this->enabled) {

Next, for the Order Total module, this was also a total re-write, then I found a better way to do this:
/includes/modules/order_total/ot_coupon.php

      $this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ' :',
                              'text' => '-' . $currencies->format($od_amount['total']),
                              'value' => $od_amount['total']);

[B]// bof: manage Free Shipping Options exclude discounts
  $_SESSION['free_shipping_options_total'] = ($order_total['total'] - $od_amount['total']);
// eof: manage Free Shipping Options exclude discounts[/B]

Now add to the checkout_payment header:
/includes/modules/pages/checkout_payment/header_php.php

// load all enabled payment modules
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());

[B]// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
  zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// eof: manage Free Shipping Options exclude discounts

[/B]require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

And finally, the Page file for the checkout_confirmation:
/includes/modules/pages/checkout_confirmation/header_php.php

if (isset($$_SESSION['payment']->flagDisablePaymentAddressChange)) {
  $flagDisablePaymentAddressChange = $$_SESSION['payment']->flagDisablePaymentAddressChange;
}

[B]// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
  zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// eof: manage Free Shipping Options exclude discounts
[/B]
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

Now, in theory a customer can come along and pick Free Shipping Options when the Total is >= 40.00 (MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) and if they then go on and add a Discount Coupon that reduces it to less than 40.00 (MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) they will be redirected back to the checkout_shipping when they try to go to the checkout_confirmation page ...

Please test this heavily to ensure that it is working correctly ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

23 Mar 2014, 8:11 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping AFTER discount codes?

Bummer this only works under some circumstances ... :eek:

Back to the drawing board ... so don't use that code as it works sometimes but not other times ... :cry:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

24 Mar 2014, 1:24 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping AFTER discount codes?

NOTE: these changes are made to files that do not have templates and overrides so be sure to save your originals and these new files as future upgrades will need similar code with possible changes to them ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

1 Apr 2014, 4:51 AM
#5
glamourdolleyes avatar

glamourdolleyes

New Zenner

Join Date:
Mar 2009
Posts:
86
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

Ok, that seems to be working but I have one issue.

I have free shipping set at $40. I have $135 in my test cart with a coupon code of 50% off. So it should be $67.50.

It is redirecting me back to shipping again even though they will have met the $40 or more requirement.

1 Apr 2014, 5:12 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping AFTER discount codes?

Let's try a few changes to the code, and be sure to test this carefully ...

On the shipping module:
/includes/modules/shipping/freeoptions.php

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

[B]// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ((isset($_SESSION['free_shipping_options_total'])) && $_SESSION['free_shipping_options_total'] > 0 && $_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && isset($_SESSION['cc_id'])) {
  $this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
[/B]
// final check for display of Free Options
      if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

[B]// bof: manage Free Shipping Options exclude discounts
//echo ' Final $_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['free_shipping_options_total'] > 0 && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
  $this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
[/B]
      if ($this->enabled) {

and in the header file for:
/includes/modules/pages/checkout_payment/header_php.php

// load all enabled payment modules
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());
[B]
// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] > 0 && ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id']))) {
  zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// eof: manage Free Shipping Options exclude discounts
[/B]
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

I have not tested this heavily, but try those changes ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

5 Apr 2014, 7:17 AM
#7
glamourdolleyes avatar

glamourdolleyes

New Zenner

Join Date:
Mar 2009
Posts:
86
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

Ok, made those changes and it seems to work but when it redirects to the shipping/delivery information page again, the free shipping options is still there. So if they continue to click free shipping it will take them in circles until they decide to pick another. Is there any way to get it to take the free shipping off the options once it brings them back?

ETA: Ok, maybe not. Even when I add enough to make it $40 AFTER the coupon code, it's still taking them back to the shipping page over and over again.

7 May 2014, 7:43 AM
#8
themaitrini avatar

themaitrini

New Zenner

Join Date:
Apr 2014
Location:
India
Posts:
5
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

Any luck on this?? Is that code working?
I have similar requirement. I got Better Together module installed on my cart (https://www.Maitrini.com), and have free shipping activated on order of more than 299. The problem I am facing is, the free shipping is applied before Better Together discount, which makes the shipping free even the final total goes below 299. Desperately waiting for any solution on this.

11 Jul 2014, 7:58 PM
#9
zartoo avatar

zartoo

New Zenner

Join Date:
Jan 2012
Posts:
9
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

anything? it will be highly appreciated if this could work!

20 Aug 2014, 3:24 PM
#10
glamourdolleyes avatar

glamourdolleyes

New Zenner

Join Date:
Mar 2009
Posts:
86
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

I actually paid someone to figure this out for me. I can attaching the php file (with his consent) but I can't figure out how. When I use the attachments it tells me:

The following errors occurred:
ot_coupon.php: Invalid File.

There is only one and it is VERY simple. When someone chooses free shipping and then uses a coupon code, an error message comes up telling them that they don't qualify for free shipping because the total is under $x and tells the customer to go back to shipping and choose a different method or add more to their cart to make it to $x.

I changed the wording just a bit which is easy, just search for it in the file.

[Attachment no longer available]

20 Aug 2014, 4:05 PM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping AFTER discount codes?

When you Reply, click on the Go Advanced to add the attachment ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 Aug 2014, 2:46 PM
#12
dysfunctional avatar

dysfunctional

Zen Follower

Join Date:
Apr 2008
Posts:
159
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

glamourdolleyes:

I actually paid someone to figure this out for me. I can attaching the php file (with his consent) but I can't figure out how. When I use the attachments it tells me:

The following errors occurred:
ot_coupon.php: Invalid File.

There is only one and it is VERY simple. When someone chooses free shipping and then uses a coupon code, an error message comes up telling them that they don't qualify for free shipping because the total is under $x and tells the customer to go back to shipping and choose a different method or add more to their cart to make it to $x.

I changed the wording just a bit which is easy, just search for it in the file.

[Attachment no longer available]

Hi glamourdolleyes, would love to have a look at your customized ot_coupon.php. I've had this issue for years, wold love to finally be able to fix it :). Thanks for your willingness to share and help others :)

Best wishes

17 Feb 2015, 5:41 PM
#13
curious avatar

curious

New Zenner

Join Date:
Aug 2011
Posts:
2
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

It looks like a few people have solved this problem that has plagued me and other for a long time. Can we please share the fix? I would love to have this implemented on our sites.

Thanks

6 Aug 2019, 8:08 PM
#14
monarchacct avatar

monarchacct

New Zenner

Join Date:
Jul 2019
Location:
Holyoke, MA
Posts:
7
Plugin Contributions:
0

Re: Free shipping AFTER discount codes?

I think this should be part of the Zen Cart core. Has anyone done this successfully? I'm very interested!