Live shipping rates with a fixed rate fall back for heavy shipments
This script is designed to run after the shipping rates are returned - specifically with an error. A second script provided below is run each time the shipping rates return, but work with the 'free ground shipping' option enabled. The script runs whenever only the free ground shipping option is returned (meaning that the live shipping rates weren't able to ship that order). Paste either option just before the closing
</head> tag of your checkout template.
You can add anything you want within that code, and it will only be run when the shipping rate requests returns with an error.
With the following option, you need to enable “Free Ground Shipping” option within the shipping section of the administration. You can rename those options to be whatever you like from within the language section also - so it could be “Large Shipment Fee” or similar.
This code works by checking the returned shipping results. If only one option is returned, it will be our 'free' option as it doesn't have any restrictions like weight or destination that the live rate carriers do. This custom option is set to whatever is set for the customFlatRate variable at the top of the script. If other options are returned with the shipping, the free option is removed to prevent people selecting it.