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

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题