1and1 Help Centre Categories

print article

How to calculate shipping cost based on a specific items in the shopping cart

Problem: You want a different shipping fee if a certain special item is added into
the shopping cart. For example: you have item1, item2 and item3. item1 and item2
are special items, and if they are added in the cart the shipping fee needs to be
calculated differently. please follow these instructions:

Create an additional item attribute for the desired items, for example, we can say bulky.
Follow FAQ How to create attributes for item rules Enter the attribute name as "bulky" and assign the value of this attribute
as "1". (You can do this for multiple items). You don't have to set up an attribute
for an a non special item. If you want to, then simply give the attribute the
value "0".

Attribute name = bulky
Attribute value = 0

Enter the following lines in basket_table.script:
(Under 'Shop design' -> 'Edit cart templates' -> 'Shopping cart table')

Enter them after $sum+= $basket_subtotal[$i];

//The items with the "bulky" feature are counted through here.
$bulky_subcounter[$i]=item_get_field('bulky',$basket_items[$i]) * item_get_field('number',$basket_items[$i]);
$bulky_counter +=$bulky_subcounter[$i];
item_set_field_type('vat', 'double', $basket_items[$i]);
Now enter the following code under 'Settings' -> 'Advanced Settings' -> 'Payment
methods' -> 'Settings for all payment methods'
Here you should see 'Rule for all payment methods': Enter the rule.

if ($bulky_counter > 0) $shipping_fee = $shipping_fee + 10;

The special shipping fee will be re-calculated when one of the specially marked
items are ordered. Please make sure that this calculation does not clash with any
other shipping fee calculations.

Please note:
If special items are not ordered then the shipping fee given for the delivery
method will be used.

The number of bulky items that the customer has placed in the basket will be in the
variable $bulky_counter. You can also use this number for calculating the shipping
costs, e.g.

if ($bulky_counter > 0) $shipping_fee=20+20*$bulky_counter;