Require a streetnumber to be added to the address field
-
Hello,
I recently implemented the WooCommerce Blocks Checkout functionality. While the beginning was great, more and more customers are not entering a house number in the address field. Previously I created a custom function that validates both the “shipping-address_1” and “billing-address_1” with a number regex and whenever a number was not found, the user would get a notice and error message.
After trying to implement this same functionality with the WooCommerce Blocks plugin I came to the conclusion that this was not possible. And because of this we are having disputes with the payment processor because of incomplete addresses.
Does anyone know if the above is possible and what the best way to implement a solution would be?
For reference this is the function I previously used:
add_action('woocommerce_checkout_process', 'custom_validation_process'); function custom_validation_process() { global $woocommerce; if(isset($_POST['shipping-address_1']) and $_POST['shipping-address_1'] != '') { if (!preg_match('/([0-9]+)/Uis', $_POST['shipping-address_1'])) { if(function_exists('wc_add_notice')) wc_add_notice( __('Please enter a house number to your address.'), 'error' ); else $woocommerce->add_error( __('Please enter a house number to your address.') ); } } if(isset($_POST['ship_to_different_address'])) { if(isset($_POST['billing-address_1']) and $_POST['billing-address_1'] != '') { if (!preg_match('/([0-9]+)/Uis', $_POST['billing-address_1'])) { if(function_exists('wc_add_notice')) wc_add_notice( __('Please enter a house number to your address.'), 'error' ); else $woocommerce->add_error( __('Please enter a house number to your address.') ); } } } }
The topic ‘Require a streetnumber to be added to the address field’ is closed to new replies.