dsk49208 2019-03-24 14:41
浏览 107
已采纳

在Woocommerce新用户注册后更新用户元数据

Im trying to add a custom field to WP_USERMETA table after Woocommerce registration

add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);

function wc_assign_custom_role($args) {
  update_user_meta($user_id, 'user_pass2', password_hash($_POST['password'], PASSWORD_DEFAULT));

  return $args;
}

as you see Im trying to capture password before hashing and save it in a different hash format in that table

but It doesnt add anything to the table

I tested the same line inside wordpress registration hook user_register and it worked but only for wordpress registration not woocommerce

UPDATE

add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);

function wc_assign_custom_role($args) {
  global $current_user;
  update_user_meta($current_user->$user_id, 'user_pass2', password_hash($_POST['password'], PASSWORD_DEFAULT));

  return $args;
}

still doesnt work

UPDATE II

function action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) { 
    update_user_meta($customer_id, 'user_pass2', password_hash($_POST['password'], PASSWORD_DEFAULT));
}; 

add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 ); 

this one create meta data but it seems it uses different $_POST['password'] rather than the password I entered, so hash something else rather than password

Any thoughts??

  • 写回答

2条回答 默认 最新

  • doujiao9426 2019-03-24 15:28
    关注

    Found the solution, We should use $_POST['account_password'] instead of $_POST['password']

    function action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) { 
        update_user_meta($customer_id, 'user_pass2', password_hash($_POST['account_password'], PASSWORD_DEFAULT));
    }; 
    
    add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 ); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog