Skip to content

Instantly share code, notes, and snippets.

@fschmittlein
Last active February 24, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fschmittlein/d00f1ccf7c1e491f05b4b82d8f970abf to your computer and use it in GitHub Desktop.
Save fschmittlein/d00f1ccf7c1e491f05b4b82d8f970abf to your computer and use it in GitHub Desktop.
Ist eine Hausnummer vorhanden?
add_action('woocommerce_checkout_process', 'custom_validation_process');
function custom_validation_process() {
global $woocommerce;
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( __('Hausnummer fehlt!'), 'error' );
else
$woocommerce->add_error( __('Hausnummer fehlt!') );
}
}
if (isset($_POST['ship_to_different_address'])) {
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( __('Hausnummer fehlt!'), 'error' );
else
$woocommerce->add_error( __('Hausnummer fehlt!') );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment