This is an old revision of the document!


Remove days timeframe from USPS rates

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 1: Add Javascript

Paste the following code in the “footer” option of the “inject custom code” template configuration option in your store's administration, or alternatively paste at the very end of the cart include template (not the cart or checkout templates):

{% if context == 'cart' or context == 'checkout' %}
<script type="text/javascript">
function customUSPSLabelFilter() {
    for (var i = 0; i < FC.json.shipping_address.shipping_results.length; i++) {
        var reg = /\d-day/i;
        var service = FC.json.shipping_address.shipping_results[i].service_name;
        if (reg.test(service)) {
            FC.json.shipping_address.shipping_results[i].service_name = service.replace(reg, "").trim();
        }
        var saved_service = FC.json.shipping_address.shipping_service_description;
        if (reg.test(saved_service)) {
            FC.json.shipping_address.shipping_service_description = saved_service.replace(reg, "").trim();
        }
    };
    FC.Template(FC.json.context).clearOutput();
    FC.cart.recalculateCartTotals();
    FC[FC.json.context].renderShippingRates(FC.json.shipping_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 %}

Site Tools