Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WooCommerce Blocks] Check if the billing address contains a house number
add_action( 'woocommerce_store_api_checkout_update_order_from_request', 'woo_blocks_address_field_validation', 10, 2);
function woo_blocks_address_field_validation( WC_Order $order, $request ) {
$billing_address = $order->get_address('billing')['address_1'];
if ( $billing_address && ! preg_match( '/[0-9]+/', $billing_address ) ) {
throw new Exception( 'Your billing address must contain a house number!' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment