Checkout field validation in WooCommerce

Checkout field validation in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

add_action( 'woocommerce_checkout_process', 'custom_checkout_field_validation', 10, 2 );
function custom_checkout_field_validation( $data, $errors ) {
    if ( ! preg_match( '/^[[email protected],]*$/', $data['billing_first_name'] ) ) {
        $errors->add( 'validation_error', __( 'Error: Only a-z, A-Z, 0-9, @, hyphens, full-stops and commas are allowed in the field.', 'woocommerce' ) );
    }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.