Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / exclude a product or category from Free Shipping freeoptions

exclude a product or category from Free Shipping freeoptions

Views: 8,903

Results 1 to 19 of 19
21 Apr 2011, 8:48 AM
#1
gotlogos avatar

gotlogos

New Zenner

Join Date:
Nov 2010
Posts:
84
Plugin Contributions:
0

exclude a product or category from Free Shipping freeoptions

I am wanting to simply be able to flag a category, in my specific case, gift cards, from being included in the cart total when determining if the customer gets free shipping or not.

I offer free shipping when the cart total goes over $57. Problem is a few people have figured out that when they add a gift card to their cart to make the total over 57.00, it triggers the free shipping.

I read a thread trying to glean some info on how to do this but the solutions they seemed to be looking for were much more complicated than what I need and felt there MUST be an easy way to do this. I simply want to eliminate a category from figuring in the total to determine if they get free shipping.

Any help would be appreciated.

21 Apr 2011, 1:11 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

You would need to adjust all the references to:
$_SESSION['cart']->show_total()

by the amount of Products that you do not allow to be counted ...

Are all of the Gift Certificates in the same Category and use the same master_categories_id on them?

23 Apr 2011, 3:42 AM
#3
gotlogos avatar

gotlogos

New Zenner

Join Date:
Nov 2010
Posts:
84
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Thanks Ajeh--yes they are all in same dedicated master category---actually I only use one product and I use attributes and price by attributes...

Ajeh:

You would need to adjust all the references to:
$_SESSION['cart']->show_total()

by the amount of Products that you do not allow to be counted ...

Are all of the Gift Certificates in the same Category and use the same master_categories_id on them?

23 Apr 2011, 3:13 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

This takes a little work ...

Let's say we do not want to have products_id 47 and 32 included in the price check when the Free Shipping in the Modules ... Order Totals ... Shipping ot_shipping is set to 50.00 and enabled ...

First, create a new file:
/includes/functions/extra_functions/reduce_free_shipping.php

and add the code:

<?php
// calculate amount not to be used for Products 186 and 10 for free shipping
  function reduce_free_shipping() {
    global $cart;
    $exclude_products = "47, 32";
    $products = $_SESSION['cart']->get_products();
    $chk_price = 0;
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      if (in_array((int)$products[$i]['id'], explode(",", $exclude_products))) {
        $chk_price += $products[$i]['final_price'] * $products[$i]['quantity'];
      }
    } // end FOR loop

    return $chk_price;
  }
?>

Next, we have to customize a few files:
/includes/modules/shipping_estimator.php

and use your templates and overrides for:
/includes/modules/your_template_dir/shipping_estimator.php

and change around line 158:

    if ( ($pass == true) && ($_SESSION['cart']->show_total() - reduce_free_shipping() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) {

Then we have to adjust the headers for the checkout_shipping, checkout_payment and checkout_confirmation ...

Change the code around line 121:
/includes/modules/pages/checkout_shipping/header_php.php

    if ( ($pass == true) && ($_SESSION['cart']->show_total() - reduce_free_shipping() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {

Change the code around line 36:
/includes/modules/pages/checkout_payment/header_php.php

if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') && $_SESSION['cart']->show_total() - reduce_free_shipping() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {

Change the code around line 43:
/includes/modules/pages/checkout_confirmation/header_php.php

if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') && $_SESSION['cart']->show_total() - reduce_free_shipping() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {

Then, what I think is the final change around line 34:
/includes/modules/order_total/ot_shipping.php

        if ( ($pass == true) && ( (($order->info['total'] - reduce_free_shipping()) - $order->info['shipping_cost']) >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {

Now, if the Order Total, less the amount of the Products with products_id 47 and 32, is >= 50.00, as set in the Shipping ot_shipping, the shipping will be Free ...

Easy smeazy, eh? :cool:

That only took all morning ... :lamo:

24 Apr 2011, 4:14 AM
#5
gotlogos avatar

gotlogos

New Zenner

Join Date:
Nov 2010
Posts:
84
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

I have never been so humbled in a long long time...I don't even know what to say but thanks...I will be making a donation to the Zen Cart project whether I can get this going or not...having a little trouble after doing all this and double/triple checking. Sent you a PM about it.

But either way many thanks.

24 Apr 2011, 1:17 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

Looking at your site it appears that you are using the Free Shipping Options freeoptions shipping module ... this is not being used for the code that I posted ...

This is setup for the Modules ... Order Total ... Shipping ot_shipping ...

Set the Free Orders for over to 57.00 and set the Enable to True ...

Does this fix things?

24 Apr 2011, 4:28 PM
#7
gotlogos avatar

gotlogos

New Zenner

Join Date:
Nov 2010
Posts:
84
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Works famously : ) Thank you...

Is there any way I can still see other shipping modules on this though...now it only shows free shipping but I'd like to be able to let them choose my flat rate which is set up for Priority at 5.00 and also to upgrade to Express if they want that?

24 Apr 2011, 4:40 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

Then we have to do it a totally different way ...

Let me give this a little thought ... :smile:

24 Apr 2011, 5:01 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

First, let's undo some code changes ...

Remove the changes from the files ...

Around line 158, remove the change:
/includes/modules/your_template_dir/shipping_estimator.php

Around line 121, remove the change:
/includes/modules/pages/checkout_shipping/header_php.php

Around line 36, remove the change:
/includes/modules/pages/checkout_payment/header_php.php

Around line 43, remove the change:
/includes/modules/pages/checkout_confirmation/header_php.php

Around line 34, remove the change:
/includes/modules/order_total/ot_shipping.php

Now, edit the file:
/includes/modules/shipping/freeoptions.php

and around line 93 change to:

            if (($_SESSION['cart']->show_total() - reduce_free_shipping()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) {

Go to Modules ... Shipping ... and install the Free Shipping Options freeoptions and set the Total >= 57.00 ...

Now, you will see all of your Shipping methods and only see the Free Shipping Options freeoptions when the Order, less anything excluded, is set >= $57.00 ...

25 Dec 2011, 9:07 PM
#10
tmacarle avatar

tmacarle

New Zenner

Join Date:
Sep 2011
Posts:
19
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Hi there,

I was wondering if there is a way to exclude an entire category from free shipping? I offer free shipping for products totaling over $100, but would like to charge shipping for 1 or 2 categories no matter how much they order. Is that possible?

Thank you,

Tom

25 Dec 2011, 10:58 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

Do the Products in those 2 Categories use those two categories_id as their master_categories_id ... :unsure:

What are you using for the Free Shipping on orders over $100 ...

27 Dec 2011, 1:52 AM
#12
tmacarle avatar

tmacarle

New Zenner

Join Date:
Sep 2011
Posts:
19
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Hi thank you for the reply. I am using "order total shipping" module. Yes, I do believe the two names are the master categories. Thanks for your help.

27 Dec 2011, 2:47 AM
#13
ajeh avatar

ajeh

Oba-san

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

Re: exclude a product or category from Free Shipping freeoptions

The easier method for Free Shipping is to use the Shipping module for Free Shipping Options freeoptions and set the Total >= 50.00 ...

The customize the code in the:
/includes/modules/shipping/freeoptions.php

and change the code to read:

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }
      if (!IS_ADMIN_FLAG) {
        global $cart;
        $chk_cat = 0;
        $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '10');
        $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '53');
        if ($chk_cat > 0) {
          $this->enabled = false;
        }
      }

What this will do is not show the Free Shipping Options when there are Products from the master_categories_id 10 or 53 in the cart and when those Products are not in the cart, then the customer will see the Free Shipping Options and the other shipping options to choose from ...

27 Dec 2011, 4:53 AM
#14
tmacarle avatar

tmacarle

New Zenner

Join Date:
Sep 2011
Posts:
19
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Thank you. I just have one more question. I found the code and am wondering how much to delete from the php. I noticed where it started, but don't know where to stop the code. This is what I see.

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

Thank you.

27 Dec 2011, 4:55 AM
#15
tmacarle avatar

tmacarle

New Zenner

Join Date:
Sep 2011
Posts:
19
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

From what I understand, I replace the entire set of what is there except the very last pointed bracket?

27 Dec 2011, 5:08 AM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: exclude a product or category from Free Shipping freeoptions

I believe you would add the code in red just before this line

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {

without deleting anything. The red code sets the $this->enabled to false in certain circumstances, so the if test will function as a switch.

27 Dec 2011, 5:12 AM
#17
tmacarle avatar

tmacarle

New Zenner

Join Date:
Sep 2011
Posts:
19
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Thank you so much, it works great! :smile:

12 Feb 2012, 5:18 PM
#18
catach avatar

catach

Zen Follower

Join Date:
Oct 2005
Posts:
101
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Ajeh:

The easier method for Free Shipping is to use the Shipping module for Free Shipping Options freeoptions and set the Total >= 50.00 ...

The customize the code in the:
/includes/modules/shipping/freeoptions.php

and change the code to read:

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

if (!IS_ADMIN_FLAG) {
global $cart;
$chk_cat = 0;
$chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '10');
$chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '53');
if ($chk_cat > 0) {
$this->enabled = false;
}
}

> 
> What this will do is not show the Free Shipping Options when there are Products from the master_categories_id 10 or 53 in the cart and when those Products are not in the cart, then the customer will see the Free Shipping Options and the other shipping options to choose from ...

Hi
Will this allow people to add products from master_categories_id 10 or 53 and have them included with the free shipping that they may have already qualified for? And/or add shipping costs only for the items that they didn't qualify for?

I am trying to enable the same scenario with 1 category for free shipping with a master_categories_id of 4. If the customer qualifies for free shipping by adding enough items from category 4 then I would like them to be able to add other items from other categories and either give free shipping on the complete order or add only the shipping costs for the added items that are not in category 4.

I would assume that I would just add a line for each category that I would like to exclude from the above php modification example. The question remains as to what happens if a customer adds items from one or more of the excluded categories as far as shipping costs?

Hope I have explained my thoughts clearly.
Thanks for any help that can be offered
John
14 Feb 2012, 12:05 AM
#19
catach avatar

catach

Zen Follower

Join Date:
Oct 2005
Posts:
101
Plugin Contributions:
0

Re: exclude a product or category from Free Shipping freeoptions

Follow-up
This above coding works great for allowing free shipping on the category ID's that are not listed. If you add something from another category your free shipping (on the items that you have already qualified for free shipping) gets "tossed out the door". It DOES NOT leave free shipping on the already qualified items and just add shipping for the items in the excluded categories. It make them all paid shipping.

Is there a way of just adding the cost of the excluded items and leave the free items as not getting added in?

Example:
$30.00 minimum for free shipping
add 6 items from the free category. subtotal $35.00 no shipping

2 items from the excluded categories subtotal $60.00 Shipping is $25.00

The above 6 items plus the 2 excluded items subtotal $95 Shipping is $25.00 (My preferred method that doesn't happen)

What it is doing is:
The above 6 items plus the 2 excluded items subtotal $95 Shipping is $40.00

Any thoughts?
John