skip to Main Content

Hello I have been having hard time solving the following problem I would like to show only order notes from woocommmerce with the value "customer_note": true , see the Json request downward

{
"id": 281,
"author": "system",
"date_created": "2017-03-21T16:46:41",
"date_created_gmt": "2017-03-21T19:46:41",
"note": "Order ok!!!",
"customer_note": false,
}

This is how the data from order notes is held in my flutter code.

  @override


Future<List<OrderNote>> getOrderNote(
      {String? userId, String? orderId}) async {
    try {
      var response = await wcApi
          .getAsync('orders/$orderId/notes?customer=$userId&per_page=20');
      var list = <OrderNote>[];
      if (response is Map && isNotBlank(response['message'])) {
        throw Exception(response['message']);
      } else {
        for (var item in response) {
//          if (item.type == 'customer') {
          /// it is possible to update to `any` note
          /// ref: https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-order-notes
          list.add(OrderNote.fromJson(item));
//          }
        }
        return list;
      }
    } catch (e) {

      rethrow;
    }
  }

2

Answers


  1. Chosen as BEST ANSWER

    I Also filter the order note containing a specific word with the following

    if (item['note'].contains('État'))
            {
            list.add(OrderNote.fromJson(item));
          } 
    

  2. What about adding a condition inside the for loop to check the value of customer_note in the item to decide whether to add it to the list or not like the following:

    for (var item in response) {
        if (item['customer_note'])
        {
            // customer_note == true
            list.add(OrderNote.fromJson(item));
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search