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? 1 How to Hide Shipping Options to PO Box Address in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/Hide-Shipping-options-1024x702.png)
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? 2 How to Hide Shipping Options to PO Box Address in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/available-SM-1024x739.png)
Instead of hiding shipping methods based on address fields, you can also hide a shipping method based on product and state field in WooCommerce.