• Resolved nerd2011

    (@dgeorge2)


    I need a way to disable PO box shipping if the chosen ship method isn’t USPS. I’ve found the code below, which disables shipping to PO Boxes, but I want to be able to ship to PO Boxes via USPS. Any suggestions would be most appreciated.

    add_action(‘woocommerce_after_checkout_validation’, ‘deny_pobox_postcode’);

    function deny_pobox_postcode( $posted ) {
    global $woocommerce;

    $address = ( isset( $posted[‘shipping_address_1’] ) ) ? $posted[‘shipping_address_1’] : $posted[‘billing_address_1’];
    $postcode = ( isset( $posted[‘shipping_postcode’] ) ) ? $posted[‘shipping_postcode’] : $posted[‘billing_postcode’];

    $replace = array(” “, “.”, “,”);
    $address = strtolower( str_replace( $replace, ”, $address ) );
    $postcode = strtolower( str_replace( $replace, ”, $postcode ) );

    if ( strstr( $address, ‘pobox’ ) || strstr( $postcode, ‘pobox’ ) ) {
    wc_add_notice( sprintf( __( “Sorry, we cannot ship to PO BOX addresses.”) ) ,’error’ );
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey there, @dgeorge2! Thanks for contacting us.

    While we can’t provide support for code customization as per our support policy, we do our best to offer advice and direct you to appropriate resources.

    You can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there too.

    I’m going to leave it open for a bit to see if anyone is able to chime in and help you out further.

    Please let us know if there’s anything else we can do to help or if you have any questions.

    Have a wonderful day!

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable PO Box Shipping for specific shipping methods’ is closed to new replies.