Remove days timeframe from USPS rates

This snippet has been replaced. In place of the following snippet, we now have a custom shipping code feature in FoxyCart 2.0 that allows you to modify returned live rates and provide custom rates to your customers without needing to add extra javascript to change the way the checkout works. Please use the new custom shipping code functionality instead of this snippet. Review this page for notes on migrating to the new functionality. This page will remain for reference.

Recently USPS reworked their priority rates to make it clearer how long a given rate will take in transit. This can be confusing for customers, especially if the products you sell don't ship straight away. This snippet removes the “1-Day”, “2-Day” etc from the rate names. For details on the changes USPS made, see their website.

Step 2: Disable Shipping Rate Signing

As this snippet will be altering the returned rates, you will need to ensure that shipping rate signing is disabled for your store. To do that, head to the “shipping” section of your store's FoxyCart administration, and at the bottom of the page ensure that “enable shipping rate signing” is disabled.

Step 2: Add Javascript

Add the following to the “custom footer” field of the “Add custom header and footer code to your templates” section in your store's FoxyCart administration, in TEMPLATES » configuration:

{% if context == 'cart' or context == 'checkout' %}
<script type="text/javascript">
function customUSPSLabelFilter(params) {
    var addresses = FC.json.has_multiship ? FC.json.multiship_data : [FC.json.shipping_address];
    if (typeof(params) == "object" && params.hasOwnProperty("address")) {
        addresses = [params.address];
    }
    $.each(addresses, function(i, address) {
        for (var i = 0; i < address.shipping_results.length; i++) {
            var reg = /\d-day/i;
            var service = address.shipping_results[i].service_name;
            if (reg.test(service)) {
                address.shipping_results[i].service_name = service.replace(reg, "").trim();
            }
            var saved_service = address.shipping_service_description;
            if (reg.test(saved_service)) {
                address.shipping_service_description = saved_service.replace(reg, "").trim();
            }
        };
        FC.Template(FC.json.context).clearOutput();
        FC.cart.recalculateCartTotals();
        FC[FC.json.context].renderShippingRates(address);
    });
}
 
FC.client.on('cart-shipping-options-update.done', customUSPSLabelFilter );
FC.client.on('checkout-shipping-options-update.done', customUSPSLabelFilter );
FC.client.on('customer-login.done', customUSPSLabelFilter );
{% if cart_is_fullpage or context == 'checkout' %}FC.client.on("ready.done",customUSPSLabelFilter);{% else %}customUSPSLabelFilter();{% endif %}
</script>
{% endif %}

Alternatively you can also add this code right at the end of the cart include template (not the cart or checkout templates, the cart include template will include it there for you).

Site Tools