Reputation: 5261
I've checked the WooCommerce documentation to see if there is a date in the refund object which I can read as date when the order was refunded:
https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Refund.html
The problem is that I can't find anything there and in the web. So is there a way to get something like the refunded date from a WooCommerce order?
So something like:
$refunds = $order->get_refunds()
$refunds->refund_date;
Upvotes: 1
Views: 1576
Reputation: 19263
Indeed there is a way. $refunds
is an array as there can be many refunds.
// Get order object (eg from id)
$order = wc_get_order( $order_id );
// Get all refunds
$refunds = $order->get_refunds();
// Loop over refunds
foreach ($refunds as $refund) {
// Old way:
echo $refund->date;
// New way (see @Yoda’s comment)
echo $refund->get_date_created()->format( 'd/m/Y' );
}
Upvotes: 4
Reputation: 5261
With the help of Christian, I've found another working solution which is a bit more compact. It only works for the first refund but in my situation I've just one refund (so all or nothing). I hope it helps someone sometimes:
// Get order object (eg from id)
$order = wc_get_order( $order_id );
// Get date from refunds in german date format
echo $order->get_refunds()[0]->get_date_created()->format( 'd.m.Y' );
Upvotes: 3