Breaking large shipments into multiple smaller packages

This snippet has been replaced. Beginning in FoxyCart 2.0, we now have basic support for breaking large shipments into multiple packages. Review the live rates section on our shipping wiki page for more details. Please use the new functionality functionality instead of this snippet. Review this page for notes on migrating to the new functionality. This page will remain for reference.

If you ship larger products, it can be entirely possible for your customers to hit the higher weight limits of the live rate shipping providers. In that instance, the customer will just see a shipping error and won't be able to select a shipping rate. To remedy that, you need to provide a smaller shipping weight, and multiply the returned rates by the amount of packages that make up the original larger weight.

Use the live rates snippet

This snippet uses another snippet to power it - namely the Live Rate Shipping Modification snippet. Add that to your store as described on that page.

Within the live rates snippet look for the code that looks like this:

FC.customLiveShipping.logic = function() {
    /* BEGIN CUSTOM SHIPPING LOGIC */
 
 
    /* END CUSTOM SHIPPING LOGIC */
};

Right after that block of code, paste the following:

FC.customLiveShipping.maximum_weight = 70; // Maximum weight allowed by your carriers
FC.customLiveShipping.package_weight = 30; // The average package size you'll send for overweight packages
FC.customLiveShipping.custom_packages = 1; // Leave this at 1
 
function overweightShippingHandler() {
    if (FC.json.total_weight_shippable > FC.customLiveShipping.maximum_weight) {
        FC.customLiveShipping.custom_packages = FC.json.total_weight_shippable/FC.customLiveShipping.package_weight;
        FC.json.shipping_address.total_weight_shippable = FC.customLiveShipping.package_weight;
    } else {
        FC.json.shipping_address.total_weight_shippable = null;
        FC.customLiveShipping.custom_packages = 1;
    }
}
 
FC.client.on('cart-shipping-options-update', overweightShippingHandler );
FC.client.on('checkout-shipping-options-update', overweightShippingHandler );
{% if cart_is_fullpage or context == 'checkout' %}FC.client.on("ready.done",overweightShippingHandler);{% else %}overweightShippingHandler();{% endif %}

Within that script, update the first two values as required:

  • FC.customLiveShipping.maximum_weight is the weight at which you want to break the order up into multiple packages. Set this to just below the maximum weight your shipping carriers allow.
  • FC.customLiveShipping.package_weight is the weight of the individual packages that you want to calculate the shipping rates at instead - multiplied the required times to meet the original total weight. Set this to a value that is as close to the average package size you'll send out as possible.

Finally - within the custom shipping logic of the live rates shipping snippet, include the following line to update all shipping rates to be multiplied by the required number of packages:

FC.customLiveShipping.update('all', '*' + FC.customLiveShipping.custom_packages);

The resulting code that you've updated from the live rates snippet should now look something like this:

The resulting code should then look something like this (making note that this will be within the rest of the live rates shipping snippet):

FC.customLiveShipping.logic = function() {
    /* BEGIN CUSTOM SHIPPING LOGIC */
 
    FC.customLiveShipping.update('all', '*' + FC.customLiveShipping.custom_packages);
 
    /* END CUSTOM SHIPPING LOGIC */
};
 
FC.customLiveShipping.maximum_weight = 70; // Maximum weight allowed by your carriers
FC.customLiveShipping.package_weight = 30; // The average package size you'll send for overweight packages
FC.customLiveShipping.custom_packages = 1; // Leave this at 1
 
function overweightShippingHandler() {
    if (FC.json.total_weight_shippable > FC.customLiveShipping.maximum_weight) {
        FC.customLiveShipping.custom_packages = FC.json.total_weight_shippable/FC.customLiveShipping.package_weight;
        FC.json.shipping_address.total_weight_shippable = FC.customLiveShipping.package_weight;
    } else {
        FC.json.shipping_address.total_weight_shippable = null;
        FC.customLiveShipping.custom_packages = 1;
    }
}
 
FC.client.on('cart-shipping-options-update', overweightShippingHandler );
FC.client.on('checkout-shipping-options-update', overweightShippingHandler );
{% if cart_is_fullpage or context == 'checkout' %}FC.client.on("ready.done",overweightShippingHandler);{% else %}overweightShippingHandler();{% endif %}

Site Tools