Skip to content

Commit ae9b6a6

Browse files
layoutdclaude
andcommitted
Add validation to prevent refunds with invalid amounts
Adds check to ensure refund amount is greater than 0 before calling wc_create_refund(). This prevents "Invalid refund amount" errors that occur when: - Orders have 100% discount coupons (total = $0) - Line items have $0 totals - Calculation results in 0 or negative amount Logs order ID, calculated amount, and order total when skipping refund. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 73cdb1b commit ae9b6a6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

includes/Generator/Order.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,17 @@ protected static function create_refund( $order, $force_partial = false ) {
521521
}
522522
}
523523

524+
// Validate refund amount is greater than 0
525+
if ( $refund_amount <= 0 ) {
526+
error_log( sprintf(
527+
'Refund skipped for order %d: Invalid refund amount (%s). Order total: %s',
528+
$order->get_id(),
529+
$refund_amount,
530+
$order->get_total()
531+
) );
532+
return false;
533+
}
534+
524535
// Create refund reason
525536
if ( $is_full_refund ) {
526537
$reason = 'Full refund';

0 commit comments

Comments
 (0)