admin管理员组文章数量:1122832
On my website I have created a register page in react and I am using Wordpress headless with WooCommerce on it.
So I was expecting to create a new user using the register page i have and as the Wordpress side is by default set to create a 'Customer" user type for any new registration.
The registration is partially working. Let me explaining. To achieve the registration I have done this:
- On wordpress, I have installed the plugin : WP Rest user from Sk8tech
- I have called the api
/wp-json/wp/v2/users/register
with a body which contain the username, email and passwork. - The new user is created and have the "Customer" type
However this new user do not shows up in the WooCommerce Customer Dashboard.
When I have installed the WooCommerce plugin, at first, I have change the type of user manually through the Wordpress dashboard from subscriber to customer and they all shows up in the Customer part.
I have notice that WooCommerce do have an api to create a new customer /wp-json/wc/v3/customers
but I cannot setup a password.
So Do I have to make 2 calls and the WooCommerce one, will automaticall create a new customer ?
Regards
On my website I have created a register page in react and I am using Wordpress headless with WooCommerce on it.
So I was expecting to create a new user using the register page i have and as the Wordpress side is by default set to create a 'Customer" user type for any new registration.
The registration is partially working. Let me explaining. To achieve the registration I have done this:
- On wordpress, I have installed the plugin : WP Rest user from Sk8tech
- I have called the api
/wp-json/wp/v2/users/register
with a body which contain the username, email and passwork. - The new user is created and have the "Customer" type
However this new user do not shows up in the WooCommerce Customer Dashboard.
When I have installed the WooCommerce plugin, at first, I have change the type of user manually through the Wordpress dashboard from subscriber to customer and they all shows up in the Customer part.
I have notice that WooCommerce do have an api to create a new customer /wp-json/wc/v3/customers
but I cannot setup a password.
So Do I have to make 2 calls and the WooCommerce one, will automaticall create a new customer ?
Regards
Share Improve this question asked Aug 31, 2020 at 6:15 SebSeb 1091 silver badge3 bronze badges1 Answer
Reset to default 0In the documentation of WP REST User https://wordpress.org/plugins/wp-rest-user/ you have the aswer:
To perform further actions after user is registered, write and add_action:
add_action('wp_rest_user_user_register', 'user_registered');
function user_registered($user) {
// Do Something
}
Replace "// Do Something" for the code to change the user role. Something like this (not tested):
$u = new WP_User( 3 ); //set your user ID
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'customer' );
本文标签: wp adminImpossible to create a new WooCommerce customer using Rest API
版权声明:本文标题:wp admin - Impossible to create a new WooCommerce customer using Rest API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736282020a1926510.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论