Offer real-time rates to customers, generate bulk order labels in one click, allow customers to track their orders, and more.
Developed by Zack Hussain @ zhmedia.ca
This module uses the USPS Web Tools API to fetch front-office rates, and the EasyPost service to purchase and print USPS labels.
The USPS Web Tools API is 100% free for unlimited rates.
The EasyPost service is free for up to 50,000 packages per year, you only have to pay them for the USPS label fee. After 50,000 packages, you’ll have to sign up for one of their plans to continue using the module. Historically, their fee has been $0.01 per label. You can contact them for more information here: https://www.easypost.com/talk-to-easypost. The module allows you to enable “Add EasyPost Label Fee to Rates” to add an extra $0.01 to the rates at checkout.
Why use both services instead of one or the other? The USPS Web Tools API does not provide permissions for creating labels to low-volume businesses. Services like EasyPost have a partnership with USPS that allows them to generate a USPS account for you with label permissions and a high-volume discount (commercial plus pricing).
The module uses USPS Web Tools API instead of EasyPost to fetch front-office rates. This is because—at the time of this writing—each rate fetched from EasyPost counts towards your 50,000 free packages per year limit. These rate fetches can add up quickly, and using USPS Web Tools ensures you are less likely to reach your EasyPost quota.
This module is not affiliated in any way with EasyPost, the EasyPost service was chosen due to its pricing and ease of integration.
Before installing the module, you will need:
The module must then be configured with your USPS Web Tools API username, your EasyPost Production and Test API keys, and your US origin address.
If you don’t have a USPS Web Tools API account, register for one at https://www.usps.com/business/web-tools-apis/welcome.htm
If you don’t have an EasyPost account, register for one at https://www.easypost.com/signup
Your EasyPost account must have a payment method on file in order to be able to purchase USPS labels from them: https://www.easypost.com/account/billing
You may have to add the free tier of the “Shipping API” subscription plan to your EasyPost account: https://www.easypost.com/account/billing
It’s strongly recommended to go through the configuration page and read what each setting does to ensure the module works exactly how you want it to.
It’s also recommended to configure default label values in the Default Label Values by Zone tab so that you don’t have to set them for every single label you create.
If you are seeing “hook” or “override” related errors while installing, please see the “Hook Related Installation Errors” section below.
In PS 1.7.0.0 to 1.7.0.5, you may need to alter one line of your theme to get the front-office order tracking feature to display properly - add “nofilter” to the following hook:
{your_theme}/templates/customer/order-detail.tpl
{$HOOK_DISPLAYORDERDETAIL}
with {$HOOK_DISPLAYORDERDETAIL nofilter}
if it is not already that way.The checkout rates can be configured by selecting the carriers you wish to enable in the Rates preferences. Enabling carriers in the Rates preferences will install them in your back-office automatically (Shipping > Carriers).
The Rates preferences include various settings for Box Packing which are explained in the next section.
If you are not seeing the rates after enabling the carriers, please see the Troubleshooting section.
The module uses your custom box dimensions to calculate shipping rates in the front-office.
You can add unlimited boxes into the module from the configuration page in the Boxes tab by clicking the “+” button. The more boxes you add, the more accurate the rates will be.
The module uses a sophisticated box packing algorithm to determine the smallest box(es) that will fit all the products in the customer’s cart; it can split the products into multiple boxes when the cart has more products than your largest box can fit.
Technical Example:
- The customer adds 2 products to their cart: a Mug (5x5x5") and a Notebook (8.5x11x1").
- You have 3 boxes in the module configuration: a Small Box (6x6x6"), a Medium Box (11x9x5") and a Large Box (12x10x8").
- The module attempts to pack the 2 products together in each of your boxes, and in this example it will choose the Large Box because: the Notebook does not fit in the Small Box; the Mug and Notebook together do not fit in the Medium Box (their combined height exceeds 5", and the Notebook cannot be oriented any other direction due to its long and flat dimensions).
- The module will fetch rates using 12x10x8" as the dimensions.
You can disable product splitting and only use 1 box for each cart by setting Box Packing Limit to 1. This will show standard rates for a single box; the module will still use box packing to determine the best box to use.
The total rate the customer sees will be a sum of the rates for all boxes the module used. The module retrieves rates from USPS for each individual box the module used; carts that require many boxes may experience a slower loading time when getting rates.
If a cart’s products require more boxes than the Box Packing Limit, the module will choose boxes that fit the largest products in the cart until it reaches the limit.
The USPS weight limit per box is 70lbs and the module will spread weight across multiple boxes if required.
The maximum limit of boxes per cart is 25. The recommended Box Packing Limit is between 5-10 to prevent slow loading times while fetching rates; only set it to more than that if you absolutely need accurate rates for 25 boxes (i.e. if you’re shipping hundreds of products per order that can cost hundreds of dollars in shipping).
The units of measurement for your boxes (e.g. in, cm) are the same as your shop’s in the “International > Localization” menu. If you change your store’s units of measurement, the module will automatically convert your boxes to the new units (provided the entered unit is valid). Be aware that you will have to manually convert your products’ dimensions yourself.
Possible Issue: If the cart contains a product that does not fit in any of your boxes, the module will be unable to pack the products into your boxes and will revert to using (1) of the largest box you have. The module will display a warning on the configuration page if any of your products are too large for your largest box.
USPS Flat Rate Boxes (and envelopes) allow you to offer flat rate USPS prices to customers at checkout, as well as purchasing flat rate labels, for certain service methods. They can be found in the “USPS Flat Rate Boxes” tab of the module configuration page.
The module will use the USPS Flat Rate Boxes the same way as your regular custom Boxes (see Boxes & Box Packing), i.e. it will attempt to pack a cart’s products inside them.
If the module determines that the smallest box that can fit the cart’s products is a USPS Flat Rate Box, the module will fetch a flat rate for that cart if available.
You can disable a USPS Flat Rate Box by clicking the green checkmark next to it, or using the “Bulk actions > Disable selection” button at the bottom of the configuration page. This will prevent flat rates from being fetched for that particular box.
If a cart’s products don’t fit in the active flat rate boxes, your custom boxes will be used instead and a regular rate will be fetched.
Tip: If you intend on using flat rates, avoid adding any custom boxes that are marginally smaller than any particular USPS Flat Rate Box. This will prevent situations where the measurements between the two boxes are so close that the module might choose a custom box over a flat rate box.
You can create a flat rate Label by selecting one of the USPS Flat Rate Boxes in the “Box” field of the label form.
If no flat rate exists for the desired USPS service method and destination, a regular Label will be created instead.
You can configure discounts for each USPS carrier in the Rate Discount Rules preferences.
Each carrier can have a percentage, dollar amount, or Free Shipping discount applied to it. e.g. Free Shipping when Order Total Is At Least USD$100.00 tax excl.
You can only create one discount rule per carrier for each Shop.
If you require more flexible ranges, consider using PrestaShop’s built-in carrier system using the following example as a starting point:
In this example we will offer free shipping for only US on orders above $100.
To display delivery time estimates on the checkout page (e.g. 3 Business Days), enable Show Delivery Time Estimates in the Rates preferences.
In PrestaShop 1.7+, you must add one line of code on your theme for this feature to work. Use the following instructions to enable delivery times.
/themes/(your_theme_name)/templates/checkout/_partials/steps/shipping.tpl
{block name='step_content'}
{if isset($delay_times)}{assign var=delivery_options value=$delay_times}{/if}
The Shipping Estimator allows guests/customers to estimate shipping fees on the Product and Cart pages. To display the Shipping Estimator, enable the Enable Shipping Estimator setting in the Rates preferences.
To estimate rates, guests without addresses can enter a Country & Zip Code.
Customers with addresses will see rates based on their account’s shipping address. They can select which address they wish to estimate shipping rates for from a drop-down list.
On the Product page, the shipping estimates are based on the product that the customer is currently viewing along with any products already in their cart, any carrier restrictions for those particular products will apply.
When a guest/customer adds a product to their cart, the Shipping Estimator will then allow the customer to change their cart’s selected shipping method from the Product or Cart pages.
Configure your addresses in the Addresses tab of the module configuration page.
Select one address as your Origin address to be used as the origin for front-office rate calculation.
If you have more than 1 address, you can select an Origin address by editing an Address and setting “Set as Origin” to “Yes”, or by clicking the red “X” icon next to an address.
Your addresses will also be available to be selected for any of the following:
You can create shipping labels on any Order page or in the “USPS > Create Label” page in the sidebar.
Creating a label will also create a Shipment in the “USPS > View Shipments” page where you can re-print, cancel/refund, or track previously created labels.
You can view real-time rates for your selected label settings by clicking “Update Rate” in the label form.
Shipments created for an Order can also be viewed on the Order’s page under the “View Shipments” tab.
Some labels, such as international labels, will have an associated Document that will be created along with the label (commercial invoice, high value report, etc). These documents typically need to be affixed to the parcel.
You can choose to include any associated Documents along with the label in the same PDF in the Labels preferences.
Shipments with associated Documents will have a Document icon under the “Docs?” column of the “View Shipments” list.
You can re-print a Document for a shipment from the “USPS > View Shipments” page, or from an Order’s page under the “View Shipments” tab, by clicking the drop-down button for a Shipment that has associated documents and clicking “Print Documents”.
You can set default values for most of the label fields for different shipping Zones in the Default Label Values by Zone preferences.
Default Label Values are used to pre-populate an Order’s label form based on the Zone of its shipping address.
Example: You want every label to require a Signature on delivery, so you set “Delivery Confirmation” to “Signature” in the Default Label Values for All Zones.
By default, the All Zones default label settings will be used for every order. Any other Zone settings that you configure, e.g. North America, will override the All Zones settings for orders with e.g. North American shipping addresses.
Example: You want to buy Insurance for every North American label, but you don’t want to buy Insurance for labels going anywhere else. You set “Insurance Amount” to “0.00” for “All Zones” and set “Insurance Amount” to your desired insurance amount, e.g. “100.00”, for “North America”.
You can create new Zones in the “International > Locations > Zones” menu.
If you want to set Default Label Values for only the US, you can create a new Zone called “United States” and edit the Country’s Zone from “North America” to “United States” in the “International > Locations > Countries” menu.
You can cancel a Shipment and request a Refund from USPS for any label within 30 days of generation that is not yet in transit.
You can refund a Shipment by locating it in the “USPS > View Shipments” page, clicking the drop-down arrow next to it, and clicking “Cancel/Refund Label”.
Refunds can take up to 15 business days for USPS to process.
A refunded Shipment will have a yellow “Pending” icon under the “Refund?” column of the “View Shipments” list while it is being processed by USPS.
Once the Refund has been accepted, the icon will automatically turn to a green “Checkmark” icon.
The Refund will be issued to your EasyPost account.
You can choose to auto-update Orders to a custom order status and auto-update an Order’s tracking number on label creation in the Labels preferences.
You can choose to automatically Send Tracking Emails on label creation in the Labels preferences. This feature uses your store’s “In Transit” email template (the same template used when manually updating an order’s tracking number) and contains a tracking link based on the carrier’s “Tracking URL” found in the Shipping > Carriers settings. Only supported in PrestaShop versions 1.7.1.0 and up.
If shipping over $2500 of goods internationally, you will need to have an Automated Export System (AES) Internal Transaction Number (ITN) and enter it in the Labels preferences. ITN will look like “AES X20120502123456”. To get an ITN, go to the AESDirect website. An ITN is required for any international shipment valued over $2,500 and/or requires an export license unless exemptions apply. The module will automatically populate this value in the EEL/PFC customs field based on the cart value.
PDFs for created labels can be found in /modules/zh_uspslabels/pdf/shipping
folder.
You can create a return label for any order that has a US shipping address.
Create a return label on an order’s individual Order page or in the USPS > Create Label page in the sidebar and changing the Label Type to “Return” under the “Parcel” tab of the label form.
Alternatively, you can choose to include a return label along with your shipping label in the “Return Label” tab of the label form. This is useful when you want to provide the customer with a return label inside the parcel that they can use to send the parcel back.
Creating a return label will create a Shipment in the “USPS > View Shipments” page. A return label will have a blue Left Arrow icon under the Return? column of the View Shipments list.
PDFs for created return labels can be found in /modules/zh_uspslabels/pdf/returns
folder.
The Bulk Labels feature allows you to create labels for multiple orders at once with powerful customization options to optimize your workflow.
You can create Bulk Labels in the “USPS > Create Bulk Order Labels” page in the sidebar.
Select multiple orders by clicking the checkboxes next to each order, or by clicking “Bulk actions > Select All” at the bottom of the page.
Filter your orders by configuring the filters at the top of the Bulk Order Labels table. Your configured filters will be saved and persist every time you visit the page until you reset them.
Create labels for the selected orders by clicking “Bulk actions > Create Labels for Selected”.
Creating labels for multiple orders will also create a Batch of labels that can be viewed and re-printed in the USPS > View Batches page in the sidebar. A Batch is a PDF containing all the labels you created that can be printed in one-shot.
If there are any Errors for one or more labels during the label creation process, those labels will be excluded from the Batch. You will be able to view the error message by clicking the red error link under the Error column. You can also view all the errors that occurred for a Batch on the USPS > View Batches page under the Errors column. Fix the errors for each order and try re-creating the labels.
PDF files for created batches of labels can be found in /modules/zh_uspslabels/pdf/batch
folder.
Note: Creating large amounts of labels may take several minutes to complete, please allow the page to finish loading and do not refresh/cancel the page load.
You can modify each individual Order’s label settings by clicking the Edit Label Settings button for the Order or from each Order’s order page.
Any modifications made to an order’s label settings will be stored permanently and will be used instead of the default label values.
Orders with modified label settings will have a pencil icon under the Modified? column and will also be indicated as modified next to Saved Changes in the label form.
Be careful when trying to change an order’s shipping address after modifying an order’s label settings. When you modify an order’s label settings, the shipping address in the label form will be stored independently from the shipping address on the customer’s order. In which case, you will then have to change the shipping address in both the Order and the Label Form Settings.
Real-time rates can be fetched for each order by clicking on the blue refresh icon under the Live Rate column.
The Label Carrier column indicates which USPS shipping method the label will use. By default, the module will automatically choose the Label Carrier based on the following in order of priority:
You can override these defaults by using Carrier Mappings in the following section.
You can map your PrestaShop carriers to USPS carriers in the Carrier Mappings preferences. Mapping your carriers will pre-select the Label Carrier for you.
Example: If you map “My Custom Carrier” to “USPS Priority Mail” - any orders that chose “My Custom Carrier” as their shipping method will have their Label Carrier defaulted to “USPS Priority Mail”.
You can configure bulk label preferences in the Bulk Order Labels preferences.
You can exclude orders with certain order statuses from showing up in the Bulk Order Labels page by selecting one or more statuses in the Exclude Order Statuses setting. Select/Deselect statuses by holding Cmd/Ctrl+Click.
Example: If you choose to exclude “Shipped” orders, they will disappear from the page after you create labels for them (provided that you have Auto-Update Order Statuses enabled in the Labels preferences). This can also speed-up the page load time as the module can ignore all your previously shipped orders.
You can choose to sort your bulk label PDFs by Order ID, Shipping Date, or Order Date (ASC/DESC).
The Delay Between Labels setting is used to slow down the label creation process when more than 60 labels are requested. This adds a delay in between each label to make sure you aren’t hitting any EasyPost API throttle limit and timing out. Increase or decrease this value depending on whether you get timed out error messages from EasyPost when creating labels.
A Scan Form is a document/manifest that can be scanned to mark all included tracking codes as “Accepted for Shipment” by USPS instead of having to scan them one at a time.
Scan Forms are not mandatory and each shipping label can already be scanned individually without a Scan Form, they are purely for convenience, organization, and saving time.
You can submit a group of Shipments to create a Scan Form in the “USPS > End of Day / Scan Form” page. Select the Shipments you wish to add to a Scan Form and click the “Bulk actions > Create Scan Form for selected” button in at the bottom of the page.
You can view all previously created Scan Forms in the “USPS > View Scan Forms” page in the sidebar.
One Scan Form will be created for each origin address used in the selected Shipments:
Example: If you shipped your shipments from 2 different locations, you’ll receive 2 different Scan Forms, each with their respective address on them.
Note: Scan Forms can only be created for shipments created on the current date that are not yet in transit. Any shipments created before the current date that were not added to a Scan Form, or shipments already in transit, can no longer be added to a Scan Form and must be scanned individually. This means that you should create a Scan Form at least once per day after you are finished creating labels. This also means that those shipments will not appear in the “End of Day / Scan Form” page.
PDFs for created scan forms can be found in /modules/zh_uspslabels/pdf/manifests/
folder.
Groups are used to group several shipments together for organizational purposes.
For example, grouping is useful for when: You have multiple fulfillment locations; You want all shipments in a group to be shipped on the same day; You want to quickly create a Scan Form/Manifest for all shipments of a certain Group.
You can choose which group a shipment will belong to when creating a shipment label. If you don’t need to group shipments, you can simply use the “Default” group for all your shipments.
You can configure your groups in the Groups preferences.
Allow customers to see their order’s tracking progress from their front-office Order Details page by enabling Enable Order Tracking in the Tracking preferences.
This will display a green progress bar in the order details page along with brief information about the last tracking event for their parcel (event description, current location, event time).
The tracking progress will only be displayed if a label was created for the order either via the Bulk Order Labels page or from the individual Order page. It will not be displayed if you created a custom label from the “Create Label & Return” page or if you entered a tracking number manually.
An order may have multiple labels associated with it, in which case the front-office order detail page will have multiple tracking progress bars (one for each label).
For PrestaShop versions 1.7.0.0 to 1.7.0.5: A theme modification may be required to make this feature work due to a bug in the default theme.
- Open the file
{your_theme}/templates/customer/order-detail.tpl
- Replace
{$HOOK_DISPLAYORDERDETAIL}
with{$HOOK_DISPLAYORDERDETAIL nofilter}
You can choose to auto-update orders to a custom order status when the USPS tracking says it has been delivered. Enable Auto-Update Order Status When Delivered in the Tracking preferences.
You can choose multiple order statuses that you want the module to track and auto-update when delivered in the Order Statuses to Track setting. Select/Deselect statuses by holding Cmd/Ctrl+Click.
The module will only track orders with those selected statuses and will ignore any orders without those statuses.
Choose which status to update an order with once it has been tracked as delivered in the Delivered Order Status setting.
The module stores rates for each cart in the database to speed up your website. It will only retrieve new rates if the customer changes their zip/postal code, the products in their cart, or the quantities for products already in their cart.
In some cases you may be trying to change the module configuration/carriers and refreshing your website to see updated rates. The rates will not update until one of the above conditions have been met, so try changing the products/quantities in your cart to see the new rates.
The module regularly cleans up old unused cache data once every 2 days to save space.
You can see the total amount of data the module is using up in the “Performance and Storage” tab of the module configuration page.
Enable Error Logging in the module configuration page to help troubleshoot rates. If there are any errors while retrieving rates, the errors will get logged in the Advanced Parameters > Logs menu. Search for "USPS" in the log page to filter your logs.
See the Smart Caching section above.
The module will only fetch new rates if the customer changes their zip/postal code, the products in their cart, or the quantities for products already in their cart. The rates will not update until one of the above conditions have been met, so try changing the products/quantities in your cart to see the new rates.
Make sure your PrestaShop admin account has the correct permissions to view the USPS pages. Your store’s “SuperAdmin” will have to modify your permissions in the “Advanced Parameters > Team > Permissions” page.
Try reinstalling the module — make sure you have “Save Info on Uninstall” enabled in the module configuration page under the “Preferences” tab so that your module data doesn’t get deleted.
The Auto-Update Order Status When Delivered feature makes use of EasyPost “webhooks”. A webhook is a way for a service such as EasyPost to automatically notify the module as soon as a tracking event occurs - the module can then in turn update the order status.
Verify the following to confirm that EasyPost is sending webhooks to your website:
Check that you have configured the Tracking settings correctly in the “Tracking” tab of the module configuration page. The desired order statuses you wish to track should be selected, use Cmd/Ctrl+Click to select/deselect multiple. Ensure that “Auto-Update Order Status When Delivered” is turned on.
Check that the “EasyPost Webhook ID” in the module configuration page under the “Preferences” tab is found in your EasyPost Production Webhooks https://www.easypost.com/account/webhooks-and-events. The Webhook ID is a long string of characters and looks like: “hook_123456780…”. If you don’t see this ID in your EasyPost Webhooks: from the above link, delete any EasyPost Webhook whose URL is pointing to the module (e.g. …/module/zh_uspslabels/webhook"), then visit the module configuration page and a new webhook should be created.
Check that EasyPost is sending “tracked.updated” events to your website in the Webhooks & Events page https://www.easypost.com/account/webhooks-and-events. You can expand each of these events to see if the module received the event, the right-hand column under “Response” should have a Body with the following: “Webhook event received by USPS module.”.
Check that your “tracked.updated” events have a status of “completed” or “pending” and not “failed” https://www.easypost.com/account/webhooks-and-events. If they have a status of “failed”, you can expand the events by clicking the “Details” button and seeing why it failed.
If your website uses HTTPS, it must have a valid and signed SSL certificate from a trusted authority in order to receive webhooks. From the EasyPost documentation: "EasyPost performs certificate validation and requires any TLS-enabled (HTTPS) webhook recipients to have a certificate signed by a public trusted certification authority. We do not support sending webhooks to over SSLv2, SSLv3, or any connection using so-called “export-grade” ciphers. For documentation on how to set up your server with TLS, we recommend Mozilla’s guide to Server-Side TLS and Qualys’s SSL/TLS deployment best practices guide."
PS versions 1.6.x and early versions of PS 1.7 contain bugs that this module must work around.
For versions 1.6.0.0 to 1.7.0.5, this module automatically installs an Override file at {your_prestashop}/override/classes/Hook.php
to solve a particular bug. An Override file is a file that a module can install that can override core PrestaShop functionality. If you’re having issues installing the module, it may be because another module has already added that file and has created a conflict.
Here are some “hook” related errors you may encounter and how to fix them:
If you encounter the error “Invalid id_module or hook_name”, try clearing your cache in Advanced Parameters > Performance and click “Clear Cache” in the top right.
If you encounter the error “The method exec in the class Hook is already overridden by the module zh_uspslabels”, try uninstalling and reinstalling the module.
If you encounter the same error as above but overridden by a module other than this one (e.g. not zh_uspslabels), this means that another module is trying to override the same file which has created a conflict, you will have to manually add one line of code yourself:
{your_prestashop}/modules/zh_uspslabels/override/classes/Hook.php
from Hook.php to Hook.php.backup (this effectively disables it){your_prestashop}/classes/Hook.php
public static function exec( $hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null ) {
Immediately after the first curly brace (" { "), make a new line, enter the following code, and save your file:
$hook_name = str_replace('\\', '', $hook_name);
It should look like the following image:
Clear your cache in “Advanced Parameters > Performance” and click “Clear Cache” in the top right. Now you shouldn’t receive any hook related errors when you reinstall the module.
If you still see the same error, add the same line of code in the file:
{your_prestashop}/override/classes/Hook.php
Previous rates-only version (“zh_uspsshipping” module):
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1