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 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)