is it possible to check an order if it contains any refund programatically?
I want to display a specific text if that is the case. So far im checking if its cancelled:
if($order->has_status('cancelled') echo "display text";
But since the order status does not change if just a single item in an order of multiple items is refunded, I cant figure how to do this.
Any Idea?
You can use WC_Order the method get_refunds()
like:
if( sizeof( $order->get_refunds() ) > 0 ) {
printf( 'Order id %s has some refund', $order->get_id() );
}
Or as a custom conditional function:
function has_refunds( $order ) {
return sizeof( $order->get_refunds() ) > 0 ? true : false;
}
Usage:
if( has_refunds( $order ) ) {
// Do something
}
Related answer thread: Get refunded orders and refunded order items details in Woocommerce 3