当前位置: 首页 > 知识库问答 >
问题:

通过函数以编程方式创建帐户

双子民
2023-03-14

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

以前有人做到过吗?我在他们网站上的WooCommerce API/函数列表中找不到任何内容。

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

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

共有2个答案

都飞跃
2023-03-14

在尝试创建新用户之前,我会查看该用户是否已经存在,并在找到时更新现有用户。get_user_by(field,value)函数返回用户对象,因此如果用户存在,则使用其id更新元字段,如果不存在,则创建一个新的元字段。

  $email = 'test@test.test';

        $address = array(
            'first_name' => 'Tester',
            'last_name'  => 'Test',
            'company'    => 'Testing, LLC',
            'email'      => $email,
            'phone'      => '777-777-777-777',
            'address_1'  => '310 S. Main Street',
            'address_2'  => '',
            'city'       => 'Las Vegas',
            'state'      => 'NV',
            'postcode'   => '89000',
            'country'    => 'US'
        );

        $default_password = wp_generate_password();
        $user = get_user_by('login', $email);

        if (!$user = $user->ID) $user = wp_create_user( $email, $default_password, $email );

        update_user_meta( $user, "billing_first_name", $address['first_name'] );
        update_user_meta( $user, "billing_last_name", $address['last_name']);
        update_user_meta( $user, "billing_company", $address['company'] );
        update_user_meta( $user, "billing_email", $address['email'] );
        update_user_meta( $user, "billing_address_1", $address['address_1']);
        update_user_meta( $user, "billing_address_2", $address['address_2'] );
        update_user_meta( $user, "billing_city", $address['city']);
        update_user_meta( $user, "billing_postcode", $address['postcode'] );
        update_user_meta( $user, "billing_country", 'US');
        update_user_meta( $user, "billing_state", $address['state'] );
        update_user_meta( $user, "billing_phone", $address['phone'] );
        update_user_meta( $user, "shipping_first_name", $address['first_name'] );
        update_user_meta( $user, "shipping_last_name", $address['last_name']);
        update_user_meta( $user, "shipping_company", $address['company'] );
        update_user_meta( $user, "shipping_address_1", $address['address_1']);
        update_user_meta( $user, "shipping_address_2", $address['address_2'] );
        update_user_meta( $user, "shipping_city", $address['city']);
        update_user_meta( $user, "shipping_postcode", $address['postcode'] );
        update_user_meta( $user, "shipping_country", 'US');
        update_user_meta( $user, "shipping_state", $address['state'] );
孟承嗣
2023-03-14

WooCommerce客户本质上是一个具有额外元数据的WordPress用户。因此,一旦创建了用户,您就可以使用update\u user\u 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_first_name
  • shipping_last_name
  • shipping_company
  • shipping_address_1
  • shipping_address_2
  • shipping_city
  • shipping_postcode
  • shipping_country
  • shipping_state
 类似资料:
  • 问题内容: 有人知道是否可以通过Java中的Google api以编程方式创建Google帐户。 问题答案: (ish) 借助Admin SDK Directory API,您可以创建可与Google工具(Gmail,日历等)一起使用的帐户,但不能使用@ gmail.com / @ googlemail.com帐户。 当新用户添加到网络和类似情况时,公司可以使用它自动为在线Google工具创建帐户

  • 我需要从php脚本手动创建一个产品(例如,我正在开发一个自定义前端表单以插入产品) 谷歌我看到一些支持论坛手动创建帖子(使用wp\u insert\u post功能)。我认为这个解决方案是不可靠的(随着woocommerce的更新,情况可能会发生变化)。 我需要一个wc函数为我做这件事,一种wc_create_product(像wc_create_order函数)。 我发现似乎是我需要的,但在网上

  • 问题内容: 我一直在尝试以编程方式重做我的应用程序上的工作。(不使用情节提要) 除了手动制作导航控制器外,我几乎完成了。 我一直在做一些研究,但找不到任何手动实现此方法的文档。(我开始将应用程序制作为单视图应用程序) 目前,我只有1个ViewController。当然是appDelegate 导航控制器将在应用程序的所有页面中使用。 如果有人可以帮助我,或发送指向一些适当文档的链接以编程方式进行此

  • 问题内容: 我知道我可以使用Java中的 api 以编程方式创建文件,如下所示: 但是是否有任何 API 可以构建树?(例如Dom之类的api) 我需要这样的东西: 和: 提前致谢。 问题答案: 由于XSLT也是XML,因此您可以简单地使用相同的策略: 等等… 但这不是很优雅。您应该改用库或框架,但应该很容易找到一个谷歌浏览器。

  • 我有一个WS,它返回非常基本的产品数据:代码、价格和图像。我需要用这些基本数据以编程方式创建Hybris产品,然后进行同步,以便在店面上看到这些产品。 创建具有这些基本信息的产品的步骤是什么?有OOTB服务吗?

  • 我正尝试使用以下命令以编程方式创建: