WooCommerce checkout fields returning false on checkout page

We are trying to validate the billing_address_1 WooCommerce checkout field to check if it contains numbers before processing the order. We have tried a number of methods to get this done but without any luck.

This standard WooCommerce method doesn’t work:

function custom_checkout_field_check() {
    // Check if set, if its not set add an error.
    if ( $_POST['billing_address_1'] && strpbrk($_POST['billing_address_1'], '1234567890') )
        wc_add_notice( __( 'Het adresveld moet minimaal een huisnummer bevatten' ), 'error' );

Check if address field 1 contains number at checkout

add_action('woocommerce_checkout_process', 'custom_checkout_field_check');

These return bool(false) on the checkout page:

var_dump($_POST['billing_address_1'] == true);
var_dump($_POST['billing_address_2'] == true);
var_dump($_POST['billing_postcode'] == true);
var_dump($_POST['billing_email'] == true);

This doesn’t work.

document.querySelector("#place_order").addEventListener("click", validateAddressField);

function validateAddressField () {
    console.log('Okay dan!');

What else can I try? What are those four fields returning bool(false)?

Read more here: WooCommerce checkout fields returning false on checkout page

Leave a Reply

Your email address will not be published. Required fields are marked *