• I am building a plugin to output accounting data to be sent to my accountant where I need to show sales.
    I have now got the situation where I need to indicate a refund.

    How can I detect when an order has been refunded – all or partially – and then get the amount of the refund.

    Obviously, as this output is month based, I need to be able to see the refund during the month that it was done, as an order could be placed one month and then the refund come in during the following month.
    For example : order paid at the end of March and then refunded in April.

    How can I do this correctly ?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    How are you getting orders currently? Refunds are a kind of order too, but created separately when performed.

    Thread Starter SimonGiddings

    (@simongiddings)

    Hi Mike,

    I am getting them via a WP_Query call, using the following args :
    ‘post_type’ => ‘shop_order’,
    ‘posts_per_page’ => -1,
    ‘post_status’ => ‘completed’,
    ‘date_query’ => array( … date specifics here … ),
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘date’

    Should I be expanding the post_type to include ‘shop_order_refund’ ?
    If so, how do I link it to the original order ?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    The query would need to be on shop_order_refund, and the post_parent of the refund is how it’s linked to the original order. You’d probably need to check for refund existence when looping over the orders you queried.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Detecting refunded orders’ is closed to new replies.