registerNewWpUser method

Future<bool> registerNewWpUser({
  1. required WooUser user,
})

Creates a new Wordpress user and returns whether action was sucessful or not using WP Rest User Wordpress plugin.

Associated endpoint : /register .

Implementation

Future<bool> registerNewWpUser({required WooUser user}) async {
  String url = this.baseUrl + URL_REGISTER_ENDPOINT;

  http.Client client = http.Client();
  http.Request request = http.Request('POST', Uri.parse(url));
  request.headers[HttpHeaders.contentTypeHeader] =
      'application/json; charset=utf-8';
  request.headers[HttpHeaders.cacheControlHeader] = "no-cache";
  request.body = json.encode(user.toJson());
  String response =
      await client.send(request).then((res) => res.stream.bytesToString());
  var dataResponse = await json.decode(response);
  _printToLog('registerNewUser response : ' + dataResponse.toString());
  if (dataResponse['data'] == null) {
    return true;
  } else {
    throw Exception(
        FlutterWooCommerceApiError.fromJson(dataResponse).toString());
  }
}