Whilst building some functionality for my pre-order system which separates out order items into individual orders with separate shipping methods I came across the need to have custom shipping methods. The vast amount of tax rules and functionality within Magento makes this seem like an incredibly complex idea, but it’s not!

We’ve got a very helpful helper function located within Mage_Tax_Helper_Data called getShippingPrice(). You can call the function using the following:

Here you can see that the function takes three arguments. The price, whether or not this already includes tax (which we can nicely pull from the configuration options) and finally the shipping address we’re dispatching this item to. This will give us the correct amount including/excluding tax depending on your Magento configuration and the selected shipping country.

The function itself builds up a request and calls a multitude of other functions which do the various calculations to determine the price. Here is this very helpful function in all it’s glory:

Dave Macaulay
Dave Macaulay
I'm an enthusiastic, slightly eccentric Magento developer who bores with the idea of another basic brief.