diff --git a/paymentiq-checkout.php b/paymentiq-checkout.php index 030d06d..287a0c0 100755 --- a/paymentiq-checkout.php +++ b/paymentiq-checkout.php @@ -237,6 +237,9 @@ public function init_hooks() { if($this->captureOnStatusComplete === 'yes') { add_action( 'woocommerce_order_status_completed', array( $this, 'paymentiq_checkout_order_status_completed' ) ); } + + add_filter( 'woocommerce_admin_order_should_render_refunds', array( $this, 'paymentiq_should_render_refund' ) ); + } /* Hook when a woo order is cancelled - if the order has a piqTxId - do a void (cancel in PIQ) */ @@ -247,6 +250,15 @@ public function init_hooks() { add_action( 'piq_co_handle_transaction_status_update', array( $this, 'handle_transaction_status_update' ) ); } + function paymentiq_should_render_refund () { + global $post; + $order_id = $post->ID; + $order = wc_get_order( $order_id ); + $order_completed = in_array( $order->get_status(), array( 'completed' ), true ); + $render_refunds = (0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded())) && $order_completed; + return $render_refunds; + } + /* When developing locally, disable trying to send emails */