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
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x