首页 文章

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

提问于
浏览
11

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

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

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

但是,我怎样才能提供其他字段详细信息(如地址) .

1 回答

  • 25

    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

    • 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

    • shipping_first_name

    • shipping_last_name

    • shipping_company

    • shipping_address_1

    • shipping_address_2

    • shipping_city

    • shipping_postcode

    • shipping_country

    • shipping_state

相关问题