Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Flat rate shipping only for certain products

Flat rate shipping only for certain products

Views: 5,116

Results 1 to 13 of 13
11 Mar 2011, 11:29 PM
#1
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Flat rate shipping only for certain products

Forgive me if this has been asked before. I was unsure what exactly to search for.

Let us say I sell shirts and pants. If a customer orders less than four shirts, I would like to give them a flat shipping rate. If a customer orders less than three shirts and a pair of pants, I would also like to give them a flat shipping rate. If a customer orders anything else, they can choose between my normal shipping options.

Is there a way to set that up?

11 Mar 2011, 11:31 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

What in the products table identifies Pants?

What identifies Shirts?

What are you "normal" shipping options?

12 Mar 2011, 2:06 AM
#3
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

What do you mean by "products table"? My normal shipping options are USPS First Class and Priority Mail. If certain products fit in flat rate boxes, I would like to give the customers that option.

12 Mar 2011, 2:59 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

You would have to identify the number of shirts and pants in the order to know what shipping module to offer ...

To do this, you have to be able to identify how many shirts and pants are in the order ...

Is there some way to identify the Shirts and Pants such as the master_categories_id in the products table?

12 Mar 2011, 12:55 PM
#5
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

I am totally lost. Does this require a bunch of custom coding?

12 Mar 2011, 1:52 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

This would require some custom code to manage whish shipping modules show based on the content of the cart ...

If you are able to identify the Products in the Shopping Cart by their Master Category ID (master_catetgories_id) you can count how many are in the cart with:
// shirts in master_categories_id 10, 12, 15
$chk_shirts = 0;
$chk_shirts += $_SESSION['cart']->in_cart_check('master_categories_id','10');
$chk_shirts += $_SESSION['cart']->in_cart_check('master_categories_id','12');
$chk_shirts += $_SESSION['cart']->in_cart_check('master_categories_id','15');

// pants in master_categories_id 2, 4, 9
$chk_pants = 0;
$chk_pants += $_SESSION['cart']->in_cart_check('master_categories_id','2');
$chk_pants += $_SESSION['cart']->in_cart_check('master_categories_id','4');
$chk_pants += $_SESSION['cart']->in_cart_check('master_categories_id','9');

Then you can tell how many shirts and pants are in the cart ...

Based on this, you could control whether you use the Flat Rate flat shipping module or your regular USPS for the shipping ...

12 Mar 2011, 5:47 PM
#7
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

So let us say I want to offer the Flat Rate shipping module to any customer who orders less than four of the soaps in this category or less than four of the soaps in this category. Would my coding look like the following?

// hand and body soap in products_id 80, 79, 81
$chk_hand_and_body_soap = 0;
$chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','80');
$chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','79');
$chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','81');

// shampoo bars in products_id 73, 74
$chk_shampoo_bars = 0;
$chk_shampoo_bars += $_SESSION['cart']->in_cart_check('master_categories_id','73');
$chk_shampoo_bars += $_SESSION['cart']->in_cart_check('master_categories_id','74');

12 Mar 2011, 6:35 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

Now you can use the results to control the $this->enabled in the shipping modules to manage which is enabled or disabled ...

What happens if they order 3 soaps in the first set and 7 soaps in the second set of soaps?

12 Mar 2011, 8:58 PM
#9
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

Ajeh:

What happens if they order 3 soaps in the first set and 7 soaps in the second set of soaps?

Oh, that would be a problem. Is there a way to make it so they can order any combination, but it has to be less than four?

12 Mar 2011, 9:30 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

Add the two calculations together and use the results to manage your code ...

12 Mar 2011, 10:28 PM
#11
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

How would I do that?

Where would this code go?

12 Mar 2011, 11:17 PM
#12
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping only for certain products

Let's say you do not want to see the Flat Rate flat shipping module if there are more than 4 Products from those master_categories_id or products_id ...

Edit the file:
/includes/modules/shipping/flat.php

and customize the code to read:

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

// bof: turn off Flat Rate if more than 4
      if (!IS_ADMIN_FLAG) {
        global $cart;
        // hand and body soap in products_id 80, 79, 81
        $chk_hand_and_body_soap = 0;
        $chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','80');
        $chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','79');
        $chk_hand_and_body_soap += $_SESSION['cart']->in_cart_check('products_id','81');

        // shampoo bars in products_id 73, 74
        $chk_shampoo_bars = 0;
        $chk_shampoo_bars += $_SESSION['cart']->in_cart_check('master_categories_id','73');
        $chk_shampoo_bars += $_SESSION['cart']->in_cart_check('master_categories_id','74');
        
        if (($chk_hand_and_body_soap + $chk_shampoo_bars > 4)) {
          $this->enabled = false;
        }
      }
// eof: turn off Flat Rate if more than 4

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

However, what is to happen if there are 4 or less of these Products in the cart plus other products? :unsure:

13 Mar 2011, 1:08 PM
#13
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Flat rate shipping only for certain products

Ajeh:

However, what is to happen if there are 4 or less of these Products in the cart plus other products? :unsure:

Ok, that looks good. I really do not know about this. Sorry, my knowledge of PHP is...well non-existent. Thank you for the patience and help so far :blush: