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 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决