2016-10-31 5 views
1

この機能を無効にすることは不可能です。私はので、私はこのフックを追加した別のデータベースに作成したユーザーID、メールとパスワードを送信しようとしている。でもex_create_new_customerZに関数名を変更Woocommerce - override wc_create_new_customer

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); 

はエラーをトリガしません。

答えて

1

私にとっては、使用するのが適切なフックではありません。 wc_create_new_customerはアクションではありません。

あなたのケースでは、のwp_insert_userの直後にトリガーとなるアクションwoocommerce _created_customerを使用することができます。 More details

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

同じ名前の新しい関数を宣言した場合wc_create_new_customer関数がオーバーライドできることに注意してください(関数はfunction_existsの文の間にあります)。この場合、WCコードと独自のコードの両方を追加する必要があります。

+0

ありがとうございます 'add_action( 'woocommerce_created_customer'、 'ex_create_ new_customer'、99,3);'が動作します – Core972

+0

リモートサーバからのデータを追加する場合に使用できるフィルタが1つありますwp_insert_userコマンドを使用します。 – Benoti