Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Created January 18, 2022 13:20
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 cubehrends/fef9c4b0f87f9c6f3f4c2e8be7f8f427 to your computer and use it in GitHub Desktop.
Save cubehrends/fef9c4b0f87f9c6f3f4c2e8be7f8f427 to your computer and use it in GitHub Desktop.
check address for required house number on WooCommerce checkout
<?php
function wdt_address_field_validation() {
$post_value = $_POST['billing_address_1'];
if ( $post_value && ! preg_match( '/[0-9]+/', $post_value ) ) {
throw new Exception( sprintf( __( 'Das Feld <strong>Straße</strong> muss eine <strong>Hausnummer</strong> beinhalten.', 'woocommerce' ) ) );
}
}
add_action('woocommerce_checkout_process', 'wdt_address_field_validation', 10, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment