2015-09-24 114 views
9

是否有任何程序化地創建客戶,就像您可以使用WordPress用戶一樣。很顯然,WooCommerce用戶共享一些相同的WordPress用戶字段,還有其他內容需要設置爲帳單/郵政地址。WooCommerce通過編程方式/通過功能創建賬戶

以前有沒有人做到這一點?我在他們的網站的WooCommerce API /函數列表中找不到任何東西。

編輯:剛剛發現這一點:http://docs.woothemes.com/wc-apidocs/function-wc_create_new_customer.html

但我怎麼能那麼提供其他現場詳細信息(如地址)。

回答

20

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_first_name
  • shipping_last_name
  • shipping_company
  • shipping_address_1
  • shipping_address_2
  • shipping_city
  • shipping_postcode
  • shipping_country
  • shipping_state
+0

完美的謝謝。我在午餐時得出了同樣的結論,但我會爲未來遇到它的用戶標記答案。 –

+0

謝謝你,快樂的編碼:) –

+0

@AnandShah你可以請回復一個鏈接,你從哪裏得到這個列表的字段?請儘快完成。 –

相關問題