Jump to content
Sign in to follow this  

Calculating Shipping based on percentage of "weight"

Recommended Posts

Hi Folks!


I've been running my store for some time using a table rate contribution that allows me to add multiple zones, and to use the modes "Weight", "Price", "Percentage", "Item-count", or "Per_Item".


I've been using the "Percentage" mode, calculating by a percentage of the order price, and that's been fine.


However, sometimes this leads to unrealistically high shipping quotes, because some of my products are light, and others heavy.


In order not to upset my set-up, which works well otherwise, I thought I might be able to calculate the shipping based on a percentage of a custom value that I would place in the "weight" column (instead of using the value in the "price" column). Just a simple change, but I'm not sure how to go about it. I've only recently begun to delve into PHP and the database itself, but will go there willingly with some help.


I would be most grateful for some direction. Thanks in advance!



Edited by WoodsWalker

Share this post

Link to post
Share on other sites

Well, necessity being the mother of invention, I eventually answered it myself! B)


The key was to look in the shipping modules I was using (the file in the table rate contribtion I am using is called "regionsclass.php", but this procedure can be adapted to most shipping modules) for:


$shipping =


In my case, this appeared in this context:


$shipping = ($regionsclass_table[$i+1] / 100) * $order_total_price;


I looked around in the code for likely possibilities, and tried replacing "$total_order_price" with a string I saw in the "weight" option part of the file, "$shipping_weight", like so:


$shipping = ($regionsclass_table[$i+1] / 100) * $shipping_weight;


...and it did exactly what I wanted. Shazam!



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this