Created
April 20, 2022 15:27
-
-
Save woogists/0823a5fba010e5d36738d121dfe8383f to your computer and use it in GitHub Desktop.
[WooCommerce Blocks] Check if the billing and shipping address contains a house number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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 ) { | |
$shipping_address = $order->get_address('shipping')['address_1']; | |
$billing_address = $order->get_address('billing')['address_1']; | |
if ( $shipping_address && ! preg_match( '/[0-9]+/', $shipping_address ) ) { | |
throw new Exception( 'Your shipping address must contain a house number!' ); | |
} | |
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