• Resolved Mark Jansen

    (@mark-jansen)


    Hello all,

    I am trying to refund an order programmatically and for that I am trying to create a script that uses WP-CLI.

    I have placed an example of my script here: https://gist.github.com/Yo…/cc5c02aa624090c453adbdf05aa7e6c5

    I have two questions about this:
    1. I can’t seem to get tax refunded
    2. How do I also refund shipping (including tax)

    The script does refund the product price, but not the tax. Even though I’ve added ‘refund_tax’ to the line items, the tax is not refunded.

    The documentation for wc_create_refund() is unfortunately very limited, so I’m hoping anyone here has done this before and might be able to tell me what I am doing wrong or where I can find the proper documentation.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Do not cross post topics and do not use Developing with WordPress for plugin specific asks. Duplicates are removed when found and I have removed yours.

    Plugin Contributor Gerhard Potgieter

    (@kloon)

    I am unable to open your Gist link as it seems to be invalid. But to add in order to refund shipping and taxes you will have to make it part of the line_items array you pass to the wc_create_refund function.

    Have a look at the the wc_create_refund function in includes/wc-order-functions.php to get an idea of what the function does.

    Thread Starter Mark Jansen

    (@mark-jansen)

    Hello Gerhard,

    Thanks for your reply.

    Hm, that’s weird. Apperently the link went wrong. Here it is:https://gist.github.com/YourMark/cc5c02aa624090c453adbdf05aa7e6c5

    As you can see there, the tax is in the line items array. Yet it’s not refunded. I know I can debug the entire function step by step. But I was hoping to find an answer here.

    I might be doing something wrong after all, or maybe some one encountered the problem before.

    • This reply was modified 6 years, 3 months ago by Mark Jansen.
    Thread Starter Mark Jansen

    (@mark-jansen)

    I have been going through it. Shipping works now, but the taxes per line still don’t.

    I really can’t wrap my head around why not. The data is passed through in all the variables through the entire process. But when the actual refund is created, it doesn’t show up.

    Thread Starter Mark Jansen

    (@mark-jansen)

    When I hook into wc_refund_created (which runs at the end of wc_create_refund()) and I check the $args, I get this:

    
    array(7) {
      ["amount"]=>
      float(52.5)
      ["reason"]=>
      string(14) "VAT correction"
      ["order_id"]=>
      string(5) "41214"
      ["refund_id"]=>
      int(0)
      ["line_items"]=>
      array(2) {
        [43380]=>
        array(3) {
          ["qty"]=>
          int(1)
          ["refund_total"]=>
          string(9) "42.216667"
          ["refund_tax"]=>
          string(8) "8.443333"
        }
        [43381]=>
        array(3) {
          ["qty"]=>
          int(1)
          ["refund_total"]=>
          string(9) "10.283333"
          ["refund_tax"]=>
          string(8) "2.056667"
        }
      }
      ["refund_payment"]=>
      bool(false)
      ["restock_items"]=>
      bool(false)
    }
    

    The tax is right there, but it doesn’t come up in the refund. This looks like a bug in WC to me.

    Thread Starter Mark Jansen

    (@mark-jansen)

    Unfortunately this still isn’t working. Does anyone have an idea? I have filed a bug report in the GIT Repository.

    I’m kind of out of ideas.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @mark-jansen It appears that you found the issue and closed your GitHub report. I will set this thread to resolved, as well.
    https://github.com/woocommerce/woocommerce/issues/22157

    Thread Starter Mark Jansen

    (@mark-jansen)

    Hello Jesse,

    yes, that is indeed the case. I’m sorry, I forgot all about this topic. Thank you. It is indeed solved.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Create refunds’ is closed to new replies.