Repository navigation
Conversation
This test was testing that after saving the order, order item discount and total was recalculated. But since we removed that functionality, this test no longer server any purpose
Testing GuidelinesHi @yuliyan @tjcafferkey , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
📝 WalkthroughWalkthroughRemoves automatic coupon recalculation from wc_save_order_items, updates a legacy unit test by deleting a coupon-related scenario, and adds a changelog entry documenting the behavior change. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Admin as Admin (WP Admin)
participant UI as Order Edit UI
participant WC as wc_save_order_items()
participant Order as WC_Order
Admin->>UI: Update order items
UI->>WC: Save items (POST)
WC->>Order: Save line items
Note over WC,Order: Coupon re-application step removed
WC->>Order: calculate_totals(false)
Order-->>WC: Totals updated (no coupon recalculation)
WC-->>UI: Response (success)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals(1 hunks)plugins/woocommerce/includes/admin/wc-admin-functions.php(0 hunks)plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php(0 hunks)
💤 Files with no reviewable changes (2)
- plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php
- plugins/woocommerce/includes/admin/wc-admin-functions.php
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: mikejolley
PR: woocommerce/woocommerce#60980
File: plugins/woocommerce/src/RestApi/Routes/V4/Orders/UpdateUtils.php:111-118
Timestamp: 2025-09-22T15:56:45.594Z
Learning: The WC_Order::recalculate_coupons() method internally handles all necessary total recalculations when coupons are updated, making additional calculate_totals() calls redundant in the coupon update flow.
Learnt from: mikejolley
PR: woocommerce/woocommerce#60980
File: plugins/woocommerce/src/RestApi/Routes/V4/Orders/UpdateUtils.php:111-118
Timestamp: 2025-09-22T15:56:45.593Z
Learning: The WC_Order::recalculate_coupons() method internally calls calculate_totals(true), so when coupon_lines are updated, order totals are automatically recalculated without needing an additional calculate_totals() call.
📚 Learning: 2025-09-22T15:56:45.594Z
Learnt from: mikejolley
PR: woocommerce/woocommerce#60980
File: plugins/woocommerce/src/RestApi/Routes/V4/Orders/UpdateUtils.php:111-118
Timestamp: 2025-09-22T15:56:45.594Z
Learning: The WC_Order::recalculate_coupons() method internally handles all necessary total recalculations when coupons are updated, making additional calculate_totals() calls redundant in the coupon update flow.
Applied to files:
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals
📚 Learning: 2025-09-22T15:56:45.593Z
Learnt from: mikejolley
PR: woocommerce/woocommerce#60980
File: plugins/woocommerce/src/RestApi/Routes/V4/Orders/UpdateUtils.php:111-118
Timestamp: 2025-09-22T15:56:45.593Z
Learning: The WC_Order::recalculate_coupons() method internally calls calculate_totals(true), so when coupon_lines are updated, order totals are automatically recalculated without needing an additional calculate_totals() call.
Applied to files:
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals
📚 Learning: 2025-09-22T15:56:45.594Z
Learnt from: mikejolley
PR: woocommerce/woocommerce#60980
File: plugins/woocommerce/src/RestApi/Routes/V4/Orders/UpdateUtils.php:111-118
Timestamp: 2025-09-22T15:56:45.594Z
Learning: The WC_Order::recalculate_coupons() method internally calls $this->calculate_totals(true) at the end of the method, so when coupon_lines are updated in REST API requests, order totals are automatically recalculated without needing an additional calculate_totals() call.
Applied to files:
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals (2)
1-1: Significance looks right."patch" matches the scope of reverting a behavior and fixing regressions.
2-2: Change Type: update → fixThis entry is a bug/regression; use Type: fix for release tooling and reader expectations.
-Significance: patch -Type: update +Significance: patch +Type: fix
| Significance: patch | ||
| Type: update | ||
|
|
||
| Don't recalculate coupons on order save, which can cause recalculation of totals and taxes when nothing changed |
There was a problem hiding this comment.
Prefix with Comment: and use imperative style (avoid contraction).
Changelog parser expects a Comment: line; without it, the entry may be ignored or rendered poorly.
Apply this diff:
-Don't recalculate coupons on order save, which can cause recalculation of totals and taxes when nothing changed
+Comment: Do not recalculate coupons on order save to avoid changing totals and taxes when nothing changed.Optionally include references (helps triage and release notes):
+Issue: #60661, #61080, #61025
+Refs: #59606, #60240📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Don't recalculate coupons on order save, which can cause recalculation of totals and taxes when nothing changed | |
| Comment: Do not recalculate coupons on order save to avoid changing totals and taxes when nothing changed. | |
| Issue: #60661, #61080, #61025 | |
| Refs: #59606, #60240 |
🤖 Prompt for AI Agents
In
plugins/woocommerce/changelog/wooplug-5447-save-order-adds-vat-to-shippingfees-and-changes-totals
around line 4, the changelog entry is missing the required "Comment:" prefix and
uses non‑imperative/contracted wording; update the line to start with "Comment:"
and rewrite the sentence in imperative, non‑contracted form (for example:
"Comment: Do not recalculate coupons on order save, which can cause
recalculation of totals and taxes when nothing has changed"). Optionally append
references or issue IDs after the Comment: line for triage and release notes.
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
yuliyan
left a comment
There was a problem hiding this comment.
Confirming the revert fixes the problems in the linked issue.
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR reverts #59606 and #60240.
The original issue was, that on an order with a coupon discount, when the quantity is changed, the discount would also change, surpassing the coupon's value. The fix was to recalculate coupons when order item is saved.
But this came with a couple of unintended side effects:
So instead of trying to fix these issue, I chose to revert the original fix, as it caused more harm than good.
Closes #60661, closes WOOPLUG-5447, closes #61080, closes WOOPLUG-5578, closes #61025, closes WOOPLUG-5563, closes #60553, closes WOOPLUG-5400, closes #61409, closes WOOPLUG-5690.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Follow steps in #61025, #60661, and #61080 that they are no longer reproducible.
Testing that has already taken place:
I've followed steps to reproduce from the above mentioned three issues to verify, they no longer were possible.