Skip to content

Commit d24ba2a

Browse files
authored
Merge pull request #399 from TycheSoftwares/refix-381
Fix #381 refund issues
2 parents aed1307 + cf24182 commit d24ba2a

File tree

15 files changed

+119
-85
lines changed

15 files changed

+119
-85
lines changed

includes/admin/views/Preview_template/default-preview-template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<?php
149149

150150
if ( count( $order->get_items() ) > 0 ) :
151+
$total_adjusted_quantity = 0;
151152
?>
152153
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
153154

@@ -158,11 +159,13 @@
158159
continue;
159160
}
160161
// Call the function to get the adjusted quantity.
161-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
162-
if ( $adjusted_qty <= 0 ) {
162+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
163+
if ( $adjusted_qty > 0 ) {
164+
$total_adjusted_quantity += $adjusted_qty;
165+
} else {
163166
continue;
164167
}
165-
$item['qty'] = $adjusted_qty;
168+
166169
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
167170
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
168171
} else {
@@ -289,7 +292,7 @@
289292
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
290293
</td>
291294
<td class="product-quantity">
292-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
295+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
293296
</td>
294297
<td class="product-price">
295298
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -310,7 +313,7 @@
310313
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
311314
<td class="total-item-price"></td>
312315
<?php if ( 'Total' === $total['label'] ) { ?>
313-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
316+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
314317
<?php } else { ?>
315318
<td class="total-quantity"></td>
316319
<?php } ?>

includes/admin/views/Preview_template/deliverynote-preview-template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
<?php
189189

190190
if ( count( $order->get_items() ) > 0 ) :
191+
$total_adjusted_quantity = 0;
191192
?>
192193
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
193194
<?php
@@ -196,11 +197,13 @@
196197
continue;
197198
}
198199
// Call the function to get the adjusted quantity.
199-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
200-
if ( $adjusted_qty <= 0 ) {
200+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
201+
if ( $adjusted_qty > 0 ) {
202+
$total_adjusted_quantity += $adjusted_qty;
203+
} else {
201204
continue;
202205
}
203-
$item['qty'] = $adjusted_qty;
206+
204207
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
205208
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
206209
} else {
@@ -217,7 +220,7 @@
217220
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
218221
</td>
219222
<td class="product-quantity">
220-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
223+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
221224
</td>
222225
<td class="product-price" v-show="deliverynote.display_price_product_table">
223226
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -238,7 +241,7 @@
238241
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
239242
<td class="total-item-price"></td>
240243
<?php if ( 'Total' === $total['label'] ) { ?>
241-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
244+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
242245
<?php } else { ?>
243246
<td class="total-quantity"></td>
244247
<?php } ?>

includes/admin/views/Preview_template/invoice-preview-template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
<?php
186186

187187
if ( count( $order->get_items() ) > 0 ) :
188+
$total_adjusted_quantity = 0;
188189
?>
189190
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
190191
<?php
@@ -193,11 +194,13 @@
193194
continue;
194195
}
195196
// Call the function to get the adjusted quantity.
196-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
197-
if ( $adjusted_qty <= 0 ) {
197+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
198+
if ( $adjusted_qty > 0 ) {
199+
$total_adjusted_quantity += $adjusted_qty;
200+
} else {
198201
continue;
199202
}
200-
$item['qty'] = $adjusted_qty;
203+
201204
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
202205
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
203206
} else {
@@ -214,7 +217,7 @@
214217
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
215218
</td>
216219
<td class="product-quantity">
217-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
220+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
218221
</td>
219222
<td class="product-price">
220223
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -236,7 +239,7 @@
236239
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
237240
<td class="total-item-price"></td>
238241
<?php if ( 'Total' === $total['label'] ) { ?>
239-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
242+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
240243
<?php } else { ?>
241244
<td class="total-quantity"></td>
242245
<?php } ?>

includes/admin/views/Preview_template/receipt-preview-template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
<?php
206206

207207
if ( count( $order->get_items() ) > 0 ) :
208+
$total_adjusted_quantity = 0;
208209
?>
209210
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
210211
<?php
@@ -213,11 +214,13 @@
213214
continue;
214215
}
215216
// Call the function to get the adjusted quantity.
216-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
217-
if ( $adjusted_qty <= 0 ) {
217+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
218+
if ( $adjusted_qty > 0 ) {
219+
$total_adjusted_quantity += $adjusted_qty;
220+
} else {
218221
continue;
219222
}
220-
$item['qty'] = $adjusted_qty;
223+
221224
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
222225
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
223226
} else {
@@ -234,7 +237,7 @@
234237
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
235238
</td>
236239
<td class="product-quantity">
237-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
240+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
238241
</td>
239242
<td class="product-price">
240243
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -256,7 +259,7 @@
256259
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
257260
<td class="total-item-price"></td>
258261
<?php if ( 'Total' === $total['label'] ) { ?>
259-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
262+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
260263
<?php } else { ?>
261264
<td class="total-quantity"></td>
262265
<?php } ?>

includes/wcdn-template-functions.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -982,18 +982,13 @@ function get_product_name( $product, $order, $item ) {
982982
/**
983983
* Function to adjust the item quantity.
984984
*
985-
* @param WC_Order $order The WooCommerce order object.
986-
* @param WC_Order_Item $item The order item object containing product details.
987-
* @param int $item_id The unique identifier for the order item.
988-
*
985+
* @param WC_Order $order The WooCommerce order object.
986+
* @param WC_Order_Item $item_id The order item object containing product details.
989987
*/
990-
function get_adjusted_item_quantity( $order, $item, $item_id ) {
988+
function get_adjusted_quantity( $order, $item_id ) {
989+
$item = $order->get_item( $item_id );
991990
$original_qty = $item->get_quantity();
992991
$qty_refunded = $order->get_qty_refunded_for_item( $item_id );
993992
$adjusted_qty = $original_qty + $qty_refunded;
994-
if ( $adjusted_qty <= 0 ) {
995-
return 0;
996-
}
997-
return $adjusted_qty;
993+
return $adjusted_qty > 0 ? $adjusted_qty : 0;
998994
}
999-
?>

templates/pdf/default/deliverynote/template.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<tbody>
101101
<?php
102102
if ( count( $order->get_items() ) > 0 ) :
103+
$total_adjusted_quantity = 0;
103104
?>
104105
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
105106
<?php
@@ -108,11 +109,12 @@
108109
continue;
109110
}
110111
// Call the function to get the adjusted quantity.
111-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
112-
if ( $adjusted_qty <= 0 ) {
112+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
113+
if ( $adjusted_qty > 0 ) {
114+
$total_adjusted_quantity += $adjusted_qty;
115+
} else {
113116
continue;
114117
}
115-
$item['qty'] = $adjusted_qty;
116118
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
117119
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
118120
} else {
@@ -129,7 +131,7 @@
129131
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
130132
</td>
131133
<td class="product-quantity">
132-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
134+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
133135
</td>
134136
<td class="product-price">
135137
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -150,7 +152,7 @@
150152
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
151153
<td class="total-item-price"></td>
152154
<?php if ( 'Total' === $total['label'] ) { ?>
153-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
155+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
154156
<?php } else { ?>
155157
<td class="total-quantity"></td>
156158
<?php } ?>

templates/pdf/default/invoice/template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<tbody>
101101
<?php
102102
if ( count( $order->get_items() ) > 0 ) :
103+
$total_adjusted_quantity = 0;
103104
?>
104105
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
105106
<?php
@@ -108,11 +109,13 @@
108109
continue;
109110
}
110111
// Call the function to get the adjusted quantity.
111-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
112-
if ( $adjusted_qty <= 0 ) {
112+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
113+
if ( $adjusted_qty > 0 ) {
114+
$total_adjusted_quantity += $adjusted_qty;
115+
} else {
113116
continue;
114117
}
115-
$item['qty'] = $adjusted_qty;
118+
116119
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
117120
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
118121
} else {
@@ -129,7 +132,7 @@
129132
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
130133
</td>
131134
<td class="product-quantity">
132-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
135+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
133136
</td>
134137
<td class="product-price">
135138
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -150,7 +153,7 @@
150153
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
151154
<td class="total-item-price"></td>
152155
<?php if ( 'Total' === $total['label'] ) { ?>
153-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
156+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
154157
<?php } else { ?>
155158
<td class="total-quantity"></td>
156159
<?php } ?>

templates/pdf/default/receipt/template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<tbody>
101101
<?php
102102
if ( count( $order->get_items() ) > 0 ) :
103+
$total_adjusted_quantity = 0;
103104
?>
104105
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
105106
<?php
@@ -108,11 +109,13 @@
108109
continue;
109110
}
110111
// Call the function to get the adjusted quantity.
111-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
112-
if ( $adjusted_qty <= 0 ) {
112+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
113+
if ( $adjusted_qty > 0 ) {
114+
$total_adjusted_quantity += $adjusted_qty;
115+
} else {
113116
continue;
114117
}
115-
$item['qty'] = $adjusted_qty;
118+
116119
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
117120
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
118121
} else {
@@ -129,7 +132,7 @@
129132
<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
130133
</td>
131134
<td class="product-quantity">
132-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
135+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
133136
</td>
134137
<td class="product-price">
135138
<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
@@ -150,7 +153,7 @@
150153
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
151154
<td class="total-item-price"></td>
152155
<?php if ( 'Total' === $total['label'] ) { ?>
153-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
156+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
154157
<?php } else { ?>
155158
<td class="total-quantity"></td>
156159
<?php } ?>

templates/pdf/simple/deliverynote/template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<?php
200200

201201
if ( count( $order->get_items() ) > 0 ) :
202+
$total_adjusted_quantity = 0;
202203
?>
203204
<?php foreach ( $order->get_items() as $item_id => $item ) : ?>
204205
<?php
@@ -207,11 +208,13 @@
207208
continue;
208209
}
209210
// Call the function to get the adjusted quantity.
210-
$adjusted_qty = get_adjusted_item_quantity( $order, $item, $item_id );
211-
if ( $adjusted_qty <= 0 ) {
211+
$adjusted_qty = get_adjusted_quantity( $order, $item_id );
212+
if ( $adjusted_qty > 0 ) {
213+
$total_adjusted_quantity += $adjusted_qty;
214+
} else {
212215
continue;
213216
}
214-
$item['qty'] = $adjusted_qty;
217+
215218
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
216219
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
217220
} else {
@@ -231,7 +234,7 @@
231234
</td>
232235
<?php } ?>
233236
<td class="product-quantity">
234-
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
237+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $adjusted_qty, $item ) ); ?></span>
235238
</td>
236239
<?php
237240
if( isset( $data['display_price_product_table']['active'] ) ) { ?>
@@ -255,7 +258,7 @@
255258
<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
256259
<td class="total-item-price"></td>
257260
<?php if ( 'Total' === $total['label'] ) { ?>
258-
<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
261+
<td class="total-quantity"><?php echo wp_kses_post( $total_adjusted_quantity ); ?></td>
259262
<?php } else { ?>
260263
<td class="total-quantity"></td>
261264
<?php } ?>

0 commit comments

Comments
 (0)