What can we help you with?

Enhance the Checkout Process for PO Box Addresses! (Code Snippet)

We often get to hear customers complaining about issues with shipment deliveries when they are not available at their physical addresses. For example, someone who spends summers in Florida and winters in Scottsdale may be getting tired of having to forward their shipments from one location to another. In addition, deliveries to inaccurate addresses might add to the trouble. Sometimes people run home-based businesses and want to separate business and personal mails. And then there are others who just wish to keep their home address private… Choosing PO Boxes appears to be a natural solution for all these cases.

A PO Box or Post Office Box is a lockable box located in a post office which customers can rent out. In the United States, PO Boxes are generally available through the United States Postal Service (USPS). Other major shipping carriers such as UPS, FedEx, DHL etc. have alternate solutions to this, but none able to directly deliver to a PO Box.

This might pose a problem when you run an online store and want to display multiple shipping options from varied carriers to your customers. If customers are choosing incorrect shipping methods, it’ll create trouble for store owners, and acts as a major hindrance to the overall shipping workflow.

For example, John is using both FedEx and USPS for his shipping needs. However, he faces a problem where his customers are continuously choosing FedEx Ground for PO Box addresses. This request cannot be fulfilled as FedEx, by law, cannot hand deliver the shipment to a US post office themselves. However, FedEx SmartPost reaches almost all U.S. addresses, including P.O. boxes and military APO, FPO and DPO destinations by utilizing the U.S. Postal Service (USPS) for final delivery. Similarly, DHL website says, “Although DHL Express cannot deliver to PO, APO, or FPO box address you may request the shipment to be held for pickup. The receiver will then be able to pickup the shipment at the local DHL Express station.” UPS too has an option where your mail and packages can be delivered to a personalized mailbox at The UPS Store.

So, among the varied list of shipping carriers, USPS is the only one permitted to use PO Boxes (rather the only one that uses PO Boxes to its fullest potential).

Since John is facing this problem continuously, he actively seeks out for a solution. He checks whether WooCommerce forums have any tweaks for this. But he couldn’t find a solution to allow PO Boxes with WooCommerce.

ELEX Solution!
Out of frustration, John decides to tackle the problem differently. Since USPS is the standard for handling PO Boxes, the solution is to limit the services of other carriers and only show USPS rates in checkout (when PO Box is entered in ‘address line 1’ instead of a street address).

ELEX helped John by developing a code snippet for this:
Go to Appearance –> Editor –> Theme Functions (functions.php) and insert the snippet to enable this functionality.

add_filter('woocommerce_package_rates', 'elex_hide_shipment', 10, 2); 
function elex_hide_shipment($available_shipping_methods, $package){

    if(isset($package['destination']) && isset($package['destination']['address'])  ){
        if(is_int(stripos($package['destination']['address'] ,'pobox'))){
            $available_shipping_methods_temp = $available_shipping_methods;
            foreach ($available_shipping_methods_temp as $shipping_method => $value) {  
                if(isset($value->label) && is_string($value->label)){
                    if(!is_int(stripos($value->label ,'USPS')) ){
    return $available_shipping_methods;

The above snippet shows only the USPS rates when a customer enters the string “pobox” in the checkout page as shown below :

John’s cart for a physical address: Note both FedEx and USPS services are displayed.

John’s cart for a PO Box address: Only USPS service is displayed.

So now, you can easily streamline your shipping based on PO Boxes and forget all about customers choosing incorrect shipping service for PO box addresses. Now make your checkout process as smooth as ever!


Explore our blog section for more related articles.

You can also check out WooCommerce and WordPress plugins in ELEX.

Previous Skip products from shipping package (Code Snippet)
You must be logged in to post a comment.