Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate birthdate field #204

Open
sibelius opened this issue Sep 6, 2021 · 1 comment
Open

validate birthdate field #204

sibelius opened this issue Sep 6, 2021 · 1 comment

Comments

@sibelius
Copy link

sibelius commented Sep 6, 2021

should it possible to validate if birthdate was filled properly before accepting it?

@rickdroio
Copy link

try this snippet:

add_action('woocommerce_checkout_process', 'validadeCheckoutFields');

function validadeCheckoutFields() {
    $billing_birthdate = filter_input(INPUT_POST, 'billing_birthdate');

    if (strlen(trim(preg_replace('/^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/', '', $billing_birthdate))) > 0) {
        wc_add_notice(__('Data de Nascimento inválido (DD/MM/AAAA)'), 'error');
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants