Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MonteLogic/cb4cb1abc8132a7d3e75a95a588528e9 to your computer and use it in GitHub Desktop.
Save MonteLogic/cb4cb1abc8132a7d3e75a95a588528e9 to your computer and use it in GitHub Desktop.
[WooCommerce Blocks] Check if the shipping address contains a house number
<?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'];
if ( $shipping_address && ! preg_match( '/[0-9]+/', $shipping_address ) ) {
throw new Exception( 'Your shipping address must contain a house number!' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment