WC Plugin: Versatile Shipping
Tech Used: PHP, JS, CSS, HTML
Are you familiar with WordPress enough to know what it’s like to install a plugin for a 3rd party service that just doesn’t work?
One of my clients needed to ship things in Canada and the USA using UPS and Canpar, and I tried multiple plugins to handle their shipping needs. Unfortunately those plugins didn’t or couldn’t work in numerous ways.
First of all, dynamic rate generators that connected to carriers via their API were always buggy. For most clients with a limited product line up, they may work fine, but this client has a wide range of products that push the specifications in every direction. I found that the generated rates would often not match those produced using the carrier calculators available on their websites. Either charging too much or too little. Often the connection would fail in some way and the carrier rates weren’t produced at all. Combining multiple products together in the cart made the rates all the more inaccurate.
Secondly, dynamic rate generators don’t account for products in the cart that fall outside of the carrier specifications, such as a product that is oversized ie over 9 feet long or 150 pounds. These oversized or overweight products require special shipping that isn’t covered by most plugins.
Thirdly, To account for special shipping needs, we assigned large fixed rates of say $299 or more to a product via shipping classes and a solid fixed rate plugin. The carrier integration plugins available simply don’t have the capability of combining specified fixed rates with dynamically generated carrier rates when products of both types are in the cart.
Lastly, dynamic rate generator plugins did not provide the functionality to provide bulk shipping discounts or per-product shipping costs.
I found that the WooCommerce plugin marketplace has plugins that specialize in fixed rate shipping, bulk shipping discounts, per product shipping rates, or [wildly inaccurate and unreliable] dynamic carrier rate generators.
That’s how Versatile Shipping was born.
I needed to build something that could fulfill every need. So I got to work and this is the result.
API-free
Versatile Shipping generates dynamic rates on the hosting server without connecting to any Carrier API. This was done primarily to ensure that customers would always see a rate generated. A consistent problem we kept having with some dynamic carrier rate plugins was that every 9th or 10th customer wouldn’t see any rates at all. Since my technical ability during the time I made this plugin paled in comparison to the plugin developers who made these buggy connections, I wasn’t prepared to figure out exactly why. Instead I opted to implement the exact pricing formula used by the carriers to generate the same shipping rates on our server as opposed to theirs.
This method was so effective, that Versatile Shipping actually produced Canpar rates that were more accurate than Canpar’s official plugin. They may have improved their plugin since then.
Carrier Calculation
The way carriers calculate rates is pretty similar- at least for the two that I made Versatile Shipping compatible with; Canpar and UPS.
First the carrier produces a Base Rate that is calculated using the “billable weight” of the cart item and the distance between the store address and the customer’s shipping address. Each address falls into a specific “shipping zone” that is variable for each store address. For a UPS example, a customer’s Austin, Texas address may fall into UPS Ground Zone 2 if the store doing the shipping is located in Texas, but it may fall into UPS Ground Zone 7 or 8 if the store is located in New York. Carriers have rate charts that assign a specific price for each pound of billable weight that increases for shipping zones that are further away from the store’s address.
Versatile Shipping uses the base rate chart in the following way. First a WooCommerce admin should create a Shipping Zone like normal in WooCommerce -> Settings -> Shipping. Ideally there would be a unique WooCommerce shipping zone per shipping zone in your carrier’s specifications. Example, WooCommerce Shipping Zone 2 for UPS Zone 2. But the zone numbers and quantities fluctuate for each rate type. UPS Ground for example (according to their 2024 Daily Rate document) has 11 zones: 2 through 8, 44, 45, and 46. UPS Next Day Air Saver though has only 7 zones: 132 through 138.
To generate a close approximation without connecting to UPS’s API, I set up 5 shipping zones in the following example: Local, Regional, National (1), National (2), and Territories/Remote. Each progressively farther away from the store’s address. A simpler setup could be Local, Regional, and National. Each zone has its state or postal codes configured to line up with an approximation of the carrier’s shipping zone. Local would be UPS Ground 2 for example, but Regional may be the average between UPS Ground 5 and UPS Ground 6 or either one. The more numerous the WooCommerce shipping zones, the more accurate the calculation will be.
The actual price per pound is not necessary to specify, since it’s a gradient between the milestones visible above. The plugin simply calculates the price for 30 pounds for example by finding the half way point between the price for 10 pounds and 50 pounds. During set up, after creating as many WooCommerce zones as desired, the admin reviews the rate chart provided by the carrier and puts the base rate in the relevant zone’s field. If we use UPS Ground for example, the base rate for 10 pounds in Zone 2 $14.29, so for the 10 pound column in the Local row, I’d put 14.29. Please note that if something higher than 1 is put in the first column, anything under that value is charged at least that value. A 5 pound product shipped to the Local zone would be charged as a 10 pound product for example.
In this way, the plugin uses shipping zones made in WooCommerce and prices inputted here, to calculate an approximate base shipping rate dynamically.
Surcharges and Measurements
Carriers charge various surcharges based upon a variety of factors. Versatile Shipping allows a surcharge to be charged for Fuel, Declared Value, Additional Handling Due to Weight, Additional Handling Due to Size, and an Additional Handling during Peak or Holiday hours. Surcharges are added if a product is over a certain size or over a certain weight. Versatile Shipping allows you to specify these parameters. Dim factor in the following example is how the carrier calculates Dimensional Weight (vs actual weight), a metric used to determine if a light product should cost more to ship, example a 7 foot long oddly shaped 3 pound product.
Combining Multiple Products
One of the areas the carrier plugins fail in, is providing reliable and accurate shipping rates for carts that have more than 1 product in them. Versatile Shipping excels at producing accurate shipping rates even if there are hundreds of products in the cart by handling products in smart ways. First products are “sorted” into those that need to be shipped individually vs those that could be shipped in a “shared” box. This is all digital and theoretical. How they’re packaged in reality is left to the client and the carrier. The individual products are those that have additional handling charges attached to them in one respect or another. Shared products are those that are “regular”, ie have no special considerations. When thinking of regular products, think of products that aren’t heavy and are less than a few feet long.
Individual products all have their prices calculated and added to the total with no additional steps. Shared products are added to the same “pseudo-boxes”. Assuming their actual dimensions do not require special consideration, they are ignored, and their volumes are added together to form a generalized-cube. This cube represents the approximate hypothetical box size the shared products could be shipped together in. The actual shape of the box may vary, but the volume should be about the same, and always be under a box size that requires additional handling.
All of the products are “packed” into these pseudo-boxes, always closing the old one and opening a new one when the pseudo-box gets almost large enough to warrant additional handling fees. In this manner, hundreds of products are packed into a handful of pseudo-boxes. It’s the pseudo-box dimensions and combined product weight that are used to calculate the rate for the box, rather than a rate being calculated for each individual regular product. After this process, the rates for every box, including those which require additional handling are tallied together and adjusted or discounted based upon the optional plugin settings.
Adjustments and Discounts
If desired Versatile Shipping allows you to adjust product shipping costs up or down. Regular products are any product that doesn’t require additional handling. ExtraCare products require additional handling. Oversized products are products that overweight or oversized. 1 is normal price, 2 is double, 0.5 is half.
Discounts can also be applied. The 20 in Large Packages Reduce Regular Shipping for example means that $20 is reduced off of the regular shipping cost for regular products if a large product is in the cart. This option emulates the concept of throwing small products into the large boxes of much larger products when shipped together. Multiple large products can often be shipped together without adding as much to the shipping rate as if they were shipped individually. The 0.25 in Multiple Large Boxes Reduction discount will make all large products in the cart have a 25% discount if there is more than 1. In addition, the optional 0.25 in Secondary Large Products Reduction reduces similarly shaped secondary instances of large products by 25%. That is, if a large product that costs $100 to ship has a quantity greater than 1, the quantity – 1 only costs $75 to ship.
Debugger
A subtle encrypted debug string is outputted at checkout that provides helpful information about the rate calculation and the cart products to the developer if necessary. For a more in-depth look, a full detail debugger can be enabled. See below for examples of both.
Per-Product Shipping Options
Entirely optional, fixed rates may be specified on a per-product basis on their respective product edit pages. The shipping of a product for each zone can be customized or even disabled. The product could be marked as free shipping to the local zone, or completely disabled for the national zone. Shipping a specific product could make everything in the cart ship for free. The Charge Cost per # field allows you to charge a custom rate for every 3 or 100 products instead of the default for each product quantity. The maximum cost is useful if you don’t want the shipping rate to go above a certain amount and a product can be marked as free shipping if shipping more than x quantity.
Conclusion
Overall, Versatile Shipping reliably generates accurate dynamic rates for regular products, while being able to seamlessly blend fixed custom rates into the total shipping price. It has solved the problems that multiple other plugins could not, improved rate accuracy, saved shipping related costs to the client, removed the bugs and customer complaints, and has removed the need to duct tape together 2 or 3 shipping solutions at checkout. It’s one of my favorite projects in terms of getting the satisfaction of solving a significant problem!