doudinghan8319 2016-11-28 19:26
浏览 29
已采纳

Wordpress Woocommerce - 用户开票Meta Update

I currently have this working example. Everything but the woocommerce meta gets updated.

Is my syntax incorrect? ( rgar is a gravity form function that returns escaped form value )

$user_id = wp_create_user( $username, $password, rgar( $entry, '4' ) );
wp_update_user( array( 
    'ID'                   => $user_id, 
    'role'                 => 'customer', //works
    'first_name'           => rgar( $entry, '1.3' ),  //works
    'last_name'            => rgar( $entry, '1.6' ),  //works
    'billing_first_name'   => rgar( $entry, '1.3' ), 
    'billing_last_name'    => rgar( $entry, '1.6' ),
    'show_admin_bar_front' => 'false', //works
    'billing_email'        => rgar( $entry, '4' ), 
    'billing_address_1'    => rgar( $entry, '3.1' ), 
    'billing_city'         => rgar( $entry, '3.3' ), 
    'billing_state'        => rgar( $entry, '3.4' ), 
    'billing_postcode'     => rgar( $entry, '3.5' ),
    'billing_phone'        => rgar( $entry, '6' )
));
update_field('field_5629452b8c7de', rgar( $entry, '1.3' ) . ' ' . rgar( $entry, '1.6' ), 'user_' . $user_id); //works
update_field('field_5629455f8c7df', rgar( $entry, '9' ), 'user_' . $user_id); //works
update_field('field_569e4be42ab47', rgar( $entry, '8' ), 'user_' . $user_id); //works
update_field('field_569e4c192ab48', str_replace('-', '', rgar( $entry, '7' )), 'user_' . $user_id); //works
  • 写回答

1条回答 默认 最新

  • dougaojue8185 2016-11-28 19:58
    关注

    Most of the things you are trying to update in wp_update_user() are user_meta fields, rather than user fields.

    ... So, you need to use:

    update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
    

    There are a few user_meta fields that wp_update_user() will automatically recognise and save in the right way, but Woocommerce's custom ones are not included there.

    So you need to update your code accordingly, to use update_user_meta(). E.g.:

    update_user_meta( $user_id, 'billing_postcode', rgar( $entry, '3.5' ) );
    

    Check here to see all user_meta fields that you can pass to the wp_update_user() function (same as those that you can pass to the wp_insert_user() function -https://codex.wordpress.org/Function_Reference/wp_insert_user#Notes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中