Title: Create refunds
Last modified: November 28, 2018

---

# Create refunds

 *  Resolved [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/)
 * 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](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](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10925309)
 * 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](https://wordpress.org/support/users/kloon/)
 * (@kloon)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10928837)
 * 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](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10929947)
 * Hello Gerhard,
 * Thanks for your reply.
 * Hm, that’s weird. Apperently the link went wrong. Here it is:[https://gist.github.com/YourMark/cc5c02aa624090c453adbdf05aa7e6c5](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 7 years, 4 months ago by [Mark Jansen](https://wordpress.org/support/users/mark-jansen/).
 *  Thread Starter [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10934650)
 * 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](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10934682)
 * 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](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10953421)
 * 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](https://wordpress.org/support/users/jessepearson/)
 * (@jessepearson)
 * Automattic Happiness Engineer
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10980504)
 * [@mark-jansen](https://wordpress.org/support/users/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](https://github.com/woocommerce/woocommerce/issues/22157)
 *  Thread Starter [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10981372)
 * 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.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 8 replies
 * 4 participants
 * Last reply from: [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/create-refunds/#post-10981372)
 * Status: resolved