1

似乎无法覆盖此功能。我正在尝试将创建的用户 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也不会触发错误。

4

1 回答 1

1

对我来说,这不是正确的钩子。wc_create_new_customer是一个函数而不是一个动作。

在您的情况下,您可以使用woocommerce _created_customerwp_insert_user. 更多细节wc_create_new_customer

add_action('woocommerce_created_customer', 'ex_create_ new_customer', 99, 3);

请注意,如果您声明具有相同名称的新函数(该函数在语句之间) ,wc_create_new_customer则可以覆盖函数。function_exists在这种情况下,您需要添加 WC 代码和您自己的代码。

于 2016-10-31T10:36:21.413 回答