Last active
July 3, 2018 19:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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