skip to Main Content

I need to remove a fee line from an order using the woocommerce REST API. I tried passing the fee_lines as an empty array, or with the name and total of the fee line set to null or zero and none of it worked. I am using the V3 Woocommerce API. Thanks

I tried to delete the fee line by:

  • removing it from the fee_lines array
  • passing the whole fee_lines array as an empty array
  • sending the id of the fee line on (no name or total)
  • setting the fee line’s name and total as null or zero

2

Answers


  1. Chosen as BEST ANSWER

    I checked the woocommerce source code and I found that there is not direct way to do that for fee lines. based on what I found , the only way to remove a fee line or shipping line is to set one of the following attributes as null method_id, product_id, title, code

    For shipping lines, we have the method_id attribute, so by setting it as null I solved the problem

    For fee lines, none of the indicated attributes belongs to the fee lines based on the documentation. so added them manually to my source code and set them to null. that way it worked and I did not have to edit the woocommerce source code

    below is the php code

    $payload['fee_lines'][$k]['method_id'] = NULL;  
    $payload['fee_lines'][$k]['product_id'] = NULL; 
    $payload['fee_lines'][$k]['title'] = NULL;  
    $payload['fee_lines'][$k]['code'] = NULL;   
    

    Thanks


  2. What endpoint are you using?

    You should be using the Update an Order endpoint. Also make sure you are using a PUT request in this case as it shows in the docs. From there you can set fee_lines to an empty array.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search