A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine. https://woocommerce.com
Find a file
Darren Ethier 3dd69708f9
Fix brand count calculation and REST API endpoint (#60158)
* Fix incorrect count for brands through the /wp-json/wc/v3/products/brands endpoint

- Changed product_brand taxonomy to use _wc_term_recount instead of _update_post_term_count
- Added product_brand to the valid taxonomies in wc_change_term_counts filter
- This ensures brand counts properly account for WooCommerce product visibility logic

* Fix brand count test to respect product visibility settings

- Use go_to() to simulate frontend context instead of admin context
- Use get_terms() instead of get_term() to trigger wc_change_term_counts filter
- Test now properly validates that brand counts respect 'hide out of stock items' setting

* Add comprehensive brand count tests for admin and frontend contexts

- Add test_brand_count_respects_product_visibility() that uses go_to() and get_terms() to simulate frontend behavior
- Add test_brand_count_ignores_product_visibility_in_admin_context() that uses get_term() to simulate admin behavior
- Tests demonstrate different behaviors: frontend respects out-of-stock settings, admin ignores them
- Both tests pass and provide complete coverage of the context-dependent behavior

* Add REST API brands controller test file

- Add comprehensive test suite for WC_REST_Product_Brands_Controller
- Tests cover brand listing, count accuracy, product visibility respect
- Includes test for brand counts respecting out-of-stock product settings
- All 5 tests pass with 29 assertions
- Provides end-to-end testing of brands API functionality

* Remove admin vs frontend context documentation from woo-phpunit rule

The context-dependent behavior documentation was removed as it was found to be inaccurate:
- is_admin() returns false in test environment, not true
- The real issue is function choice (get_terms vs get_term), not context
- Simplified rule to focus on core testing practices

* Remove duplicate product_brand filter from WC_Brands class

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

* Delete plugins/woocommerce/changelog/fix-wooplug-5231-incorrect-count-for-brands-through-the-wp

Remove superfluous changelog added by AI.

* update brands rest controller test to remove unnecessary setup

* Update doc block for method to include Brands

* Add test for deleting product a brand is attached to.

* Simplify the tests with helper for getting first brand term.

* Add test for visibility affected count on  specific brand REST request.

* Move tests to category controller.

The brands controller extends the category controller so this ensures tests live in the appropriate place.

As a part of this refactor I also improved some of the test architecture and removed superfluous term_cache clears (WP scaffolding already clears caches on tearDown).

---------

Co-authored-by: github-actions <github-actions@github.com>
2025-08-11 14:01:24 -04:00
.cursor/rules Fix brand count calculation and REST API endpoint (#60158) 2025-08-11 14:01:24 -04:00
.github Add slack notifications for open issues prior to release build. (#60272) 2025-08-11 07:55:17 -04:00
.husky [dev] Update wireit output dependencies sync at pnpm install (#55095) 2025-02-05 10:28:11 +01:00
bin [dev] Release: canonical extensions testing workflow tweaks (#59618) 2025-07-14 08:42:45 +02:00
docs Product Collection: enable carousel layout option to users (#60267) 2025-08-11 10:55:49 +02:00
packages Prepare Packages for Release (#60291) 2025-08-11 11:23:38 +02:00
plugins Fix brand count calculation and REST API endpoint (#60158) 2025-08-11 14:01:24 -04:00
tools Remove changelog entries from intermediate branches (#59562) 2025-07-16 15:35:33 +02:00
.codecov.yml [dev] [6] Monorepo: drop unsupported @woocommerce/api-core-tests package. (#58647) 2025-06-10 19:38:33 +02:00
.coderabbit.yml Configure coderabbit to be more defensive in PR reviews (#59374) 2025-07-07 17:02:38 -04:00
.editorconfig JS formatting files 2021-10-19 10:35:46 +13:00
.eslintignore [testing workflows] Add optional jobs in CI workflow (#47414) 2024-05-16 13:31:17 -07:00
.eslintrc.js Designate root level eslint config 2021-12-13 08:13:40 -08:00
.gitattributes Use ci-jobs Utility For ci.yml Matrix (#43532) 2024-01-12 20:32:14 -08:00
.gitignore Add .claude to .gitignore (#58646) 2025-06-11 14:24:25 +02:00
.markdownlint.json Update Markdown lint allowing the same headings if they're not siblings (#51438) 2024-09-17 12:44:15 +02:00
.markdownlintignore undo changes to test fixtures 2023-11-10 15:49:08 +01:00
.npmrc [dev] Monorepo: disable update notification from pnpm (#54721) 2025-01-21 12:28:46 +01:00
.nvmrc Update the monorepo to node v20 (#45148) 2024-04-12 13:49:55 -03:00
.pnpmfile.cjs Incubate interactivity API fork in WooCommerce (behind feature flag) (#57611) 2025-05-16 20:26:45 +12:00
.prettierrc.js JS formatting files 2021-10-19 10:35:46 +13:00
.stylelintrc Deprecate stylelint-config-wordpress with current package 2021-12-14 09:14:54 -08:00
.syncpackrc [dev] Monorepo: drop cross-env dependency. (#58919) 2025-06-17 15:15:20 +02:00
changelog.txt Update changelog.txt 2025-07-31 08:00:42 +01:00
CODE_OF_CONDUCT.md Update @woo.com email addresses to @woocommerce.com (#46387) 2024-04-19 21:11:01 +00:00
CODEOWNERS Codeowners for cart/checkout/StoreAPI (#59167) 2025-06-30 12:27:15 +01:00
DEVELOPMENT.md Fix markdown typos. (#50282) 2024-08-19 14:59:10 -03:00
package.json [dev] Full revert of #59334 (#59365) 2025-07-02 15:44:04 +02:00
phpcs.xml add exclusion for short array syntax 2023-12-14 10:07:41 -04:00
pnpm-lock.yaml Email Editor: Fix block theme styles interference and refactor block functionality (#60024) 2025-07-29 08:07:32 +01:00
pnpm-workspace.yaml [Monorepo] Merge Blocks Library into the WooCommerce Plugin (#54911) 2025-03-05 12:06:42 +01:00
README.md Update social link to @DevelopWoo and reflect Twitter's rebranding to X (#59511) 2025-07-10 12:52:28 -04:00
renovate.json Converted Spaces To Tabs In JSON 2022-05-10 13:31:01 -07:00
SECURITY.md Update SECURITY.md (#56914) 2025-04-01 17:41:39 +01:00
tsconfig.base.json [dev] [1] Monorepo: drop unsupported @woocommerce/admin-e2e-tests package. (#58638) 2025-06-10 15:51:03 +02:00

WooCommerce Monorepo

WooCommerce

Welcome to the WooCommerce Monorepo on GitHub. Here you can find all of the plugins, packages, and tools used in the development of the core WooCommerce plugin as well as WooCommerce extensions. You can browse the source, look at open issues, contribute code, and keep tracking of ongoing development.

We recommend all developers to follow the WooCommerce development blog to stay up to date about everything happening in the project. You can also follow @DevelopWoo on X (formerly Twitter) for the latest development updates.

Getting Started

To get up and running within the WooCommerce Monorepo, you will need to make sure that you have installed all of the prerequisites.

Prerequisites

  • NVM: While you can always install Node through other means, we recommend using NVM to ensure you're aligned with the version used by our development teams. Our repository contains an .nvmrc file which helps ensure you are using the correct version of Node.
  • PNPM: Our repository utilizes PNPM to manage project dependencies and run various scripts involved in building and testing projects.
  • PHP 7.4+: WooCommerce Core currently features a minimum PHP version of 7.4. It is also needed to run Composer and various project build scripts. See troubleshooting for troubleshooting problems installing PHP.
  • Composer: We use Composer to manage all of the dependencies for PHP packages and plugins.

Note: A POSIX compliant operating system (e.g., Linux, macOS) is assumed. If you're working on a Windows machine, the recommended approach is to use WSL (available since Windows 10).

Once you've installed all of the prerequisites, the following will prepare all of the build outputs necessary for development:

# Ensure that correct version of Node is installed and being used
nvm install
# Install the PHP and Composer dependencies for all of the plugins, packages, and tools
pnpm install -frozen-lockfile
# Build all of the plugins, packages, and tools in the monorepo
pnpm build

Repository Structure

Each plugin, package, and tool has its own package.json file containing project-specific dependencies and scripts. Most projects also contain a README.md file with any project-specific setup instructions and documentation.

  • Plugins: Our repository contains plugins that relate to or otherwise aid in the development of WooCommerce.
    • WooCommerce Core: The core WooCommerce plugin is available in the plugins directory.
  • Packages: Contained within the packages directory are all of the PHP and JavaScript provided for the community. Some of these are internal dependencies and are marked with an internal- prefix.
  • Tools: We also have a growing number of tools within our repository. Many of these are intended to be utilities and scripts for use in the monorepo, but, this directory may also contain external tools.

If you'd like to learn more about how our monorepo works, please check out this guide here.

Reporting Security Issues

To disclose a security issue to our team, please submit a report via HackerOne here.

Support

This repository is not suitable for support. Please don't use our issue tracker for support requests, but for core WooCommerce issues only. Support can take place through the appropriate channels:

NOTE: Unfortunately, we are unable to honor support requests in issues on this repository; as a result, any requests submitted in this manner will be closed.

Community

For peer to peer support, real-time announcements, and office hours, please join our slack community!

Contributing to WooCommerce

As an open source project, we rely on community contributions to continue to improve WooCommerce. To contribute, please follow the pre-requisites above and visit our Contributing to Woo doc for more links and contribution guidelines.