Handle partial/full refund for orders containing free items

Also adds helper method to determine if such as free item exists or
not. Closes #9460
This commit is contained in:
Mike Jolley 2015-10-29 15:34:33 +00:00
parent 871c8591f0
commit 5b6e16682c
2 changed files with 16 additions and 9 deletions

View File

@ -1941,24 +1941,31 @@ abstract class WC_Abstract_Order {
/**
* Returns true if the order contains a downloadable product.
*
* @return bool
*/
public function has_downloadable_item() {
$has_downloadable_item = false;
foreach ( $this->get_items() as $item ) {
$_product = $this->get_product_from_item( $item );
if ( $_product && $_product->exists() && $_product->is_downloadable() && $_product->has_file() ) {
$has_downloadable_item = true;
return true;
}
}
return false;
}
return $has_downloadable_item;
/**
* Returns true if the order contains a free product
* @since 2.5.0
* @return bool
*/
public function has_free_item() {
foreach ( $this->get_items() as $item ) {
if ( ! $item['line_total'] ) {
return true;
}
}
return false;
}
/**

View File

@ -2264,7 +2264,7 @@ class WC_AJAX {
}
// Trigger notifications and status changes
if ( $order->get_remaining_refund_amount() > 0 || $order->get_remaining_refund_items() > 0 ) {
if ( $order->get_remaining_refund_amount() > 0 || ( $order->has_free_item() && $order->get_remaining_refund_items() > 0 ) ) {
/**
* woocommerce_order_partially_refunded
*