Skip to content

[Backport to release/10.1] Update OrderCountCache to return values for all previously saved statuses #60236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2025

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 6, 2025

This PR is a cherry-pick of #60209 to release/10.1.

Original PR Description

Changes proposed in this Pull Request:

This updates the OrderCountCache::get() method so that it returns all previously stored values for a given order type.

Previously, if $order_statuses were not passed in, the list of statuses that would be fetched from cache would be based on the default list of statuses retrieved from wc_get_order_statuses(). This causes a backward compatibility issue with extensions like WooCommerce Subscriptions which doesn't register all of the statuses it uses to be returned by wc_get_order_statuses().

This changes it so that the OrderCountCache will keep it's own list of saved statuses per order type allowing OrderCountCache->get() to return all previously saved counts for the order type.

Partial Fix for WOOSUBS-867.

This specifically fixes an issue with WooCommerce Subscriptions when running object cache.

(For Bug Fixes) Bug introduced in PR #54034.

To See Previous Bug:

  1. Make sure you have at least 2 active subsccriptions.
  2. Go to WP-Admin -> WooCommerce -> Subscriptions.
  3. Set the screen options -> items per page to less than than the number of active subcriptions you have setup.
  4. Choose to display only Active subscriptions.
  5. Without this patch, the pagination for Active subscriptions will not show because the cached count is not currently being returned for that status.

Screenshots or screen recordings:

Before After

How to test the changes in this Pull Request:

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

  1. Make sure you have at least 2 active subsccriptions.
  2. Go to WP-Admin -> WooCommerce -> Subscriptions.
  3. Set the screen options -> items per page to less than than the number of active subcriptions you have setup.
  4. Choose to display only Active subscriptions.
  5. The pagination for Active subscriptions should correctly show as the cached count is now returned for that status.

Note - The cached count shown within pagination WooCommerce Subscriptions does not get properly updated when a subscription is transitioned from one status to another. This is noted in https://github.com/woocommerce/woocommerce-subscriptions/pull/4973#issuecomment-3154877832. Because Woo Subscriptions overrides the transition method of its extended order, it will need to integrate cache incrementing itself.

Testing that has already taken place:

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

Changelog Entry Comment

Comment

…uses (#60209)

* Update OrderCountCache to return values for all previously saved statuses.

* Switch to set_multiple so that status cache doesn't need to be set multiple times

* Fix call to ensure_statuses_for_type within set

* Add some type safety

* Add test for unregistered cache counts

* lint fixes

* more lint fixes

* another equal alignment

* add separator to statuses cache key

* Deprecate get_default_statuses() method

* remove short array syntax

* Address feedback, move private property back to top of class and fix deprecation version
@prettyboymp prettyboymp merged commit e2c423a into release/10.1 Aug 8, 2025
47 of 49 checks passed
@prettyboymp prettyboymp deleted the cherry-pick-PR60209-to-release/10.1 branch August 8, 2025 14:08
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Aug 8, 2025
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant