Checkout Integration Address Verification Script

POCMicrosc
New Community Member

Good morning,

I am trying to bar non-residential addresses from being able to checkout through PayPal, as we do not dispatch to PO Boxes, Mail forwarding etc.

 

I have implemented a script which checks the address fields on the checkout page for certain keywords, and flags an error to woocommerce based on this, preventing checkout.

This works fine for the inline card payments and bitcoin gateway I use, but Paypal steams ahead unperturbed.  Is it possible to implement something like the Validation Script in PayPal documentation which instead references the 'error' output of my current php script?

 

Script below for reference

add_action('woocommerce_after_checkout_validation', 'poc_disallow_nonres_shipping' );
  
function poc_disallow_nonres_shipping( $posted ) {
   $address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
   $address2 = ( isset( $posted['shipping_address_2'] ) ) ? $posted['shipping_address_2'] : $posted['billing_address_2'];
   $replace = array( " ", ".", "," );
   $address = strtolower( str_replace( $replace, '', $address ) );
   $address2 = strtolower( str_replace( $replace, '', $address2 ) );
   
   $keywords = array("pobox", "dpd", "parcel", "unit", "wizard", "suite", "tnt", "hermes");

   foreach ($keywords as $keyword) {
       if ( strstr( $address, $keyword ) || strstr( $address2, keyword ) ) {
      wc_add_notice( 'Sorry, we only ship to residential addresses.', 'error' );
   }
}
}

Any help much appreciated!

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.