Shipping based on weight

Is it possible to calculate shipping based on the weight / quantity of products in the basket? Cheers!

Not cleanly in 2.4. It’s on the list to enable dynamic shipping costs based on weight or destination.

There’s a work around where you can use AJAX in the cart or checkout phase to hit up some custom code that calculates the price. That piece of code should create a new simpleCartMethod object with the shipping price, and return the ID of that method into the cart/checkout. Then back on the client-side adding that ID to a hidden input deliveryMethod will process it with the checkout.

That sounds cool. I was going to change the _getDeliveryMethods function to look up the cart contents and output the correct delivery method. There are only three options based on price so the plan was to only output the one that related to the weight. Does that sound feasible or am I asking for trouble?

Changing core methods is definitely asking for trouble :wink:

Do you have an example of the work around? Would another option be to have all methods available but hidden then use JS to show the one that relates to the weight of the cart?

Unfortunately no I don’t have an example for the workaround, though I do know people have used it.

A JS based approach might work as well, just want to make sure to also test it with javascript disabled so something server-side might be better :wink:

Sorted. Added weight to the product option then wrote a snippet to calculate the weight based on the items in the cart. Each delivery method has the weight as part of the name so used a conditional statement in the tpl to only add the applicable delivery method to the checkout. Job done. Thanks for the help Mark - glad I didn’t mess with the core code!

1 Like