Skip to content

[Performance] - Remove unnecessary calculate_totals() call in CartCoupons DELETE handler#63404

Merged
senadir merged 3 commits intowoocommerce:trunkfrom
Abdalsalaam:fix/delete-cart-coupons-performance
Mar 6, 2026
Merged

[Performance] - Remove unnecessary calculate_totals() call in CartCoupons DELETE handler#63404
senadir merged 3 commits intowoocommerce:trunkfrom
Abdalsalaam:fix/delete-cart-coupons-performance

Conversation

@Abdalsalaam
Copy link
Copy Markdown
Contributor

@Abdalsalaam Abdalsalaam commented Feb 22, 2026

Submission Review Guidelines:

Changes proposed in this Pull Request:

DELETE /wc/store/v1/cart/coupons called $cart->calculate_totals() after removing all coupons, but the result was never used, the endpoint immediately returns an empty []response body with no cart totals.

  • This PR removes the unnecessary calculate_totals() call from CartCoupons::get_route_delete_response().
  • The next consumer request (GET /cart) will trigger recalculation via CartController::get_cart_for_response() as designed.
  • AbstractCartRoute::cart_updated() documents this explicitly: "This does not trigger a recalculation of the cart, endpoints should have already done so before returning the cart response."

(For Bug Fixes) Bug introduced in PR # .

Screenshots or screen recordings:

N/A — logic change, no visual output.

Before After

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a coupon in WooCommerce admin (e.g. SAVE10).
  2. Add a product to the cart and apply the coupon via POST /wc/store/v1/cart/coupons with body {"code": "SAVE10"}.
  3. Call GET /wc/store/v1/cart and note the discounted totals, confirm SAVE10 appears in the coupon list.
  4. Call DELETE /wc/store/v1/cart/coupons and confirm the response is 200 [].
  5. Call GET /wc/store/v1/cart again and confirm the coupon list is empty and totals reflect full price with no discount.

Testing that has already taken place:

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Remove unnecessary calculate_totals() call from DELETE /wc/store/v1/cart/coupons. The result was never used since the endpoint returns an empty response body.

Changelog Entry Comment

Comment

@Abdalsalaam Abdalsalaam requested a review from a team as a code owner February 22, 2026 20:41
@Abdalsalaam Abdalsalaam requested review from opr and removed request for a team February 22, 2026 20:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 22, 2026

Testing Guidelines

Hi @woocommerce/rubik,

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:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@github-actions github-actions Bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 22, 2026
@woocommercebot woocommercebot requested review from a team, ObliviousHarmony and kmanijak and removed request for a team February 22, 2026 20:42
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Removes a redundant calculate_totals() call from the DELETE cart coupons endpoint, since the endpoint returns an empty response body. Includes a changelog entry documenting this performance-focused change.

Changes

Cohort / File(s) Summary
Cart Coupons Delete Endpoint Optimization
plugins/woocommerce/changelog/63404-fix-delete-cart-coupons-performance, plugins/woocommerce/src/StoreApi/Routes/V1/CartCoupons.php
Removed unnecessary calculate_totals() call from the delete coupon response handler and added corresponding patch changelog entry noting the performance improvement.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description provides detailed context about the change, including the problem statement, implementation details, and comprehensive testing instructions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: removing an unnecessary calculate_totals() call from the CartCoupons DELETE handler, which is a clear performance optimization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Abdalsalaam Abdalsalaam changed the title Remove unnecessary calculate_totals() call in CartCoupons DELETE handler [Performance] - Remove unnecessary calculate_totals() call in CartCoupons DELETE handler Feb 22, 2026
@kmanijak kmanijak removed their request for review February 23, 2026 09:45
@senadir senadir enabled auto-merge (squash) March 6, 2026 15:39
@senadir senadir merged commit 50a794d into woocommerce:trunk Mar 6, 2026
32 checks passed
@github-actions github-actions Bot added this to the 10.7.0 milestone Mar 6, 2026
samnajian pushed a commit that referenced this pull request Mar 11, 2026
…pons DELETE handler (#63404)

* remove unnecessary calculate_totals

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
jamesckemp pushed a commit that referenced this pull request Mar 11, 2026
…pons DELETE handler (#63404)

* remove unnecessary calculate_totals

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
@Abdalsalaam Abdalsalaam deleted the fix/delete-cart-coupons-performance branch April 27, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants