Skip to content

Instantly share code, notes, and snippets.

@mateusneves
Last active July 3, 2018 19:43
Show Gist options
  • Save mateusneves/dcb5a0bd82653345cb8910202d29ce30 to your computer and use it in GitHub Desktop.
Save mateusneves/dcb5a0bd82653345cb8910202d29ce30 to your computer and use it in GitHub Desktop.
Action para não permitir que uma conta seja cadastrada no Woocommerce com um CPF ou CNPJ já existente.
<?php
/*
Action para não permitir que uma conta seja cadastrada no Woocommerce com um CPF ou CNPJ já existente.
Esta action adiciona esta condicional para o campo de CPF ou CNPJ inserido pelo do plugin Extra Checkout Fields for Woocommerce
Você pode inserir este código no arquivo functions.php do seu tema.
*/
add_action('woocommerce_checkout_process', 'check_if_cpf_cnpj_exists');
function check_if_cpf_cnpj_exists() {
if( isset( $_POST['billing_cpf'] ) ){
$label = "CPF";
$args = array(
'meta_key' => 'billing_cpf',
'meta_value' => $_POST['billing_cpf']
);
}elseif( isset( $_POST['billing_cnpj'] ) ){
$label = "CNPJ";
$args = array(
'meta_key' => 'billing_cnpj',
'meta_value' => $_POST['billing_cnpj']
);
}
$user_cpf_cnpj_exists = get_users( $args );
if ( $user_cpf_cnpj_exists )
wc_add_notice( 'Já existe uma conta cadastrada com o ' . $label . ' informado.', 'error' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment