1and1 Help Centre Categories

print article

How to calculate shipping costs based on certain weight

Problem: You want different shipping cost for different weights. Say for example,
you sell books, you can then assign different weights for different books. And at
the end of the order, the weights are calculated and based on the weight the
shipping fee is calculated.

Set up additional attributes for the items in question. You can call it "weight".
Follow FAQ How to create attributes for item rulesThe attribute name is "weight", and you can assign different values for different
items. For example, book1 has weight 2 and book 3 has weight 4. It is not important
that you enter weights for all the items.

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':


$weight=0;
foreach ($basket_items as $i) {
//Weight calculated here.
$overall_weight+= item_get_field('weight', $i) * item_get_field('count', $i);
}

if ($overall_weight > 30) $shipping_fee = 15.00;
elseif ($overall_weight > 20) $shipping_fee = 13.00;
elseif ($overall_weight > 10) $shipping_fee = 11.00;
Tip
If none of the above conditions apply then the shipping costs given with your
delivery method will be charged.

If you want to change the shipping costs relatively, you could write the following:
$shipping_fee= $shipping_fee + 10;

You can also calculate shipping costs depending on the weight and the country the
items are being shipped to. Under 'Settings' -> 'Advanced Settings' -> 'Basic Setting' ->
'Other shop settings'
you will find Swap the first and second pages of the order process? Choose Yes.
Also check FAQ How do I calculate shipping fee based on the Country of Delivery?


if (get_orderinfo_shipping_field("country"))
$country= get_orderinfo_shipping_field("country");
else
$country= get_orderinfo_field("country");

$weight=0;
foreach ($basket_items as $i) {
//Weight calculate here.
$overall_weight+= item_get_field('weight', $i) * item_get_field('count', $i);
}

if ($country="UK" && $overall_weight > 30) $shipping_fee= 15.00;
elseif ($country="UK" && $overall_weight > 20) $shipping_fee= 12.00;
elseif ($country="US" && $overall_weight > 30) $shipping_fee= 25.00;
elseif ($country="US" && $overall_weight > 20) $shipping_fee= 20.00;

Please note:
If a shopper orders items that has a total weight of 50 and lists the shipping
country as India (INst of countries for country selection') the shipping fee will be £20.00
You can find the country codes at:
'Settings' -> 'Advanced Settings' -> 'Text modules 1' -> Texts for the country, state, and province lists'
Here you can see 'List of countries for country selection'