Checkout Integration Address Verification Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Labels:
-
Express Checkout
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- PayPal subscriptions have stopped working. Error on PayPal's site in Merchant Products and Services Archives
- Get Access Token through login in Merchant Products and Services Archives
- Authentication failing with PayPal Checkout Server Integration in Merchant Products and Services Archives
- express checkout: on live mode appears step with button "return to merchant/seller" in Merchant Products and Services Archives
- paying without using a Paypal account in Merchant Products and Services Archives