How are partial refunds stored in the WooCommerce Database?
Partial refund orders are stored in database like normal ones: In wp_posts
table with a 'post_type' = 'shop_order_refund'
and a 'post_parent' = order_ID (number)
, where the order_ID
is the reference to the original 'shop_order'
.
To find out which one of this refunds are partial, you need the _refund_amount
amount value that you can find under wp_post_meta
for this 'refund_order'
and his corresponding 'shop_order'
with the _order_total
value too:
if ( 'refund_order'
=> _refund_amount
) != ( 'shop_order'
=> _order_total
) :then it's partial.
if ( 'refund_order'
=> _refund_amount
) == ( 'shop_order'
=> _order_total
) :then it's normal (not partial).
Notes:
- You can have one or many partial refunds for one order.
- There is for refund orders an
_order_total
item inwp_postmeta
table with a negative value that is always reflecting the positive value of_refund_amount
item. This_order_total
value has nothing to do with the related parent'shop_order' => '_order_total'
value.It's the opposite (negative) value of the related parent
'shop_order' => '_order_total'
value only when refund order IS NOT PARTIAL. - In
wp_woocommerce_order_items
andwp_woocommerce_order_itemmeta
tables, there is related detailed data concerning products in orders and refunded orders...