我启用WooCommerce rest API,并生成consumer_key和consumer_secret。我正在开发WooCommerce商店本地移动应用程序。我正在研究“我的帐户” WooCommerce rest API登录页面和注册表格,但看不到解决方案。因此,如果有人对“我的帐户”页面登录和注册API有想法,请提出解决方案。
最诚挚的问候, Ketan。
==>首先安装此https://wordpress.org/plugins/json-api-user/插件
==> 注册API:
在注册调用之前,将生成以下用于New nonce的API:
https://site_URL/api/get_nonce/?controller=user&method=register
之后,使用以下API进行注册:
==> 登录API:
add_action( 'rest_api_init','register_api_hooks' ); function register_api_hooks() { register_rest_route( 'custom-plugin','/login/',array( 'methods' => 'GET','callback' => 'login',) ); }
function login($request){
$creds = array();
$creds['user_login'] = $request["username"];
$creds['user_password'] = $request["password"];
$creds['remember'] = true;
$user = wp_signon( $creds,false );
if ( is_wp_error($user) )
echo $user->get_error_message();
return $user;
}
add_action( 'after_setup_theme','custom_login' );