覆盖此功能似乎是不可能的。我正在尝试将创建的用户ID,邮件和密码发送到另一个数据库,所以我添加了这个钩子:
function ex_create_new_customer( $email, $username = '', $password = '' ) {
// add to datastory BD
/* GenSalt */
$string = str_shuffle(mt_rand());
$salt = uniqid($string ,true);
$rounds = 12;
$crypted_password = crypt($_POST['password'], '$2y$'. $rounds . '$' . $salt);
/*request sql*/
$servername = "server_address";
$username = "my_user";
$passworddb = "user_pass_for_db";
$conn = new PDO("mysql:host=$servername;dbname=db_name", $username, $passworddb);
try {
$conn->exec("INSERT INTO user(user_nom, user_prenom, user_mdp, user_mail ) VALUES('".$_POST['billing_last_name']."', '".$_POST['billing_first_name']."', '".$crypted_password."', '0', '".$_POST['email']."')");
} catch(PDOException $e) {
die( $e->getMessage() );
}
}
add_action( 'wc_create_new_customer', 'ex_create_new_customerZ', 1 , 3 );
即使将函数名称更改为ex_create_new_customerZ
也不会触发错误。
答案 0 :(得分:1)
对我而言,它不是正确使用的钩子。 wc_create_new_customer
是一项功能而非行动。
在您的情况下,您可以使用woocommerce _created_customer
wp_insert_user
之后触发的操作wc_create_new_customer
。 More details
add_action('woocommerce_created_customer', 'ex_create_ new_customer', 99, 3);
注意,如果声明一个具有相同名称的新函数(函数在wc_create_new_customer
语句之间),则可以覆盖function_exists
函数。在这种情况下,您需要添加WC代码和您自己的代码。