wordpress - WooCommerce 以编程方式/通过功能创建帐户

标签 wordpress woocommerce account

无论如何,是否可以像使用 WordPress 用户一样以编程方式创建客户。显然 WooCommerce 用户共享一些相同的 WordPress 用户字段,还有其他内容需要设置,例如帐单/邮政地址。

有没有人以前实现过这个?我在他们网站上的 WooCommerce API/功能列表中找不到任何内容。

编辑:刚刚发现这个:http://docs.woothemes.com/wc-apidocs/function-wc_create_new_customer.html

但是我如何才能提供其他字段详细信息(如地址)。

最佳答案

WooCommerce 客户本质上是具有额外元数据的 WordPress 用户。因此,一旦创建了用户,您就可以使用 update_user_meta 向其添加元数据。功能。导航到用户 -> 所有用户,编辑用户之一,然后向下滚动以查看字段。

编写下面给出的代码,为您提供其工作原理的要点。

$user_id = wc_create_new_customer( $email, $username, $password );

update_user_meta( $user_id, "billing_first_name", 'God' );
update_user_meta( $user_id, "billing_last_name", 'Almighty' );
.... more fields

这是帐单和运输字段的完整列表

计费
  • billing_first_name
  • billing_last_name
  • billing_company
  • billing_address_1
  • billing_address_2
  • billing_city
  • billing_postcode
  • billing_country
  • billing_state
  • billing_email
  • billing_phone

  • 航运
  • 航运名字
  • 航运姓氏
  • 航运公司
  • shipping_address_1
  • shipping_address_2
  • Shipping_city
  • 航运邮政编码
  • 航运国家
  • 航运状态
  • 关于wordpress - WooCommerce 以编程方式/通过功能创建帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32758253/

    相关文章:

    wordpress - 如何在 Centos 上将 htaccess 转换为 nginx 重写?

    php - WooCommerce:检查产品是否具有特定属性

    wordpress - 强制 Docker 在主机而不是 guest 中挂载代码卷

    php - 对于特定国家/地区,在 Woocommerce 结账时将城市替换为所选的州值

    c# - UWP : Get the current UserName to provide rights to the user

    jquery - wordpress联系表单7下拉选择将值填充到输入框中

    php - 在 Woocommerce 中按 _sale_price_dates_to 获取两周前的产品 ID(orig_offer_product_id 除外)

    linux在同一主目录上单独的用户配置文件

    ios - 如何检查哪个分发证书签署了 .ipa?

    php - 使用 ajax 为 WooCommerce 产品创建过滤器选择器