Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide Shipping Options to PO Box Address in WooCommerce?

The ability to hide shipping methods based on the presence of PO Boxes in address fields is an easy option now. The code snippets let you hide shipping options when the customer enters a PO Box in the shipping address.

add_filter('woocommerce_package_rates', 'ts_disable_shipping_for_po_box', 10, 2);

function ts_disable_shipping_for_po_box($rates, $package) {
    // Check if the 'PO BOX' is present in the shipping address
    $shipping_address = $package['destination']['address'];

    if (strpos($shipping_address, 'PO BOX') !== false) {
        // If 'PO BOX' is present, unset all shipping methods
        $rates = array();
    }

    return $rates;
}

Output

If a customer inputs a PO Box in the address fields, the available shipping options will not be displayed.

How to Hide Shipping Options to PO Box Address in WooCommerce? - Tyche Softwares

Other than PO Box, if any other address is entered it will show the default available shipping methods.

How to Hide Shipping Options to PO Box Address in WooCommerce? - Tyche Softwares

Instead of hiding shipping methods based on address fields, you can also hide a shipping method based on product and state field in WooCommerce.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.