Commit ac5f820
Fix refund amount validation to prevent exceeding order total
The "Invalid refund amount" error occurred because calculated refund amounts slightly exceeded the available order total due to rounding errors in tax calculations.
Changes:
- Calculate maximum refundable amount (order total - already refunded)
- Cap refund amount to maximum available before calling wc_create_refund()
- Round both calculated refund and max refund to 2 decimal places
- Improve error logging to show order total and already refunded amounts
Example of the issue:
- Order total: $24851.03
- Calculated refund (with 3 decimal tax): $24851.04
- Result: $0.01 over limit → "Invalid refund amount" error
This fix ensures refunds never exceed the mathematically available amount, preventing WooCommerce validation errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent ae9b6a6 commit ac5f820
1 file changed
+18
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
524 | 536 | | |
525 | 537 | | |
526 | 538 | | |
527 | | - | |
| 539 | + | |
528 | 540 | | |
529 | 541 | | |
530 | | - | |
| 542 | + | |
| 543 | + | |
531 | 544 | | |
532 | 545 | | |
533 | 546 | | |
| |||
556 | 569 | | |
557 | 570 | | |
558 | 571 | | |
559 | | - | |
| 572 | + | |
560 | 573 | | |
561 | 574 | | |
562 | 575 | | |
| 576 | + | |
| 577 | + | |
563 | 578 | | |
564 | 579 | | |
565 | 580 | | |
| |||
0 commit comments