On November 3, WooCommerce announced a public package of automated PHP stubs for extensions. WooCommerce PHP stubs give PHPStan information about extension classes and methods, so developers can check integration code without installing every extension in their analysis environment.
The package addresses a familiar blind spot in static analysis: when an analyzer cannot see another plugin’s code, calls into it may be skipped or baselined. WooCommerce’s new package provides generated stubs for supported extensions, with version-specific files developers can include in their PHPStan configuration.
In brief: The package is available through GitHub and Packagist and covers Woo-owned paid Marketplace plugins, free Woo-owned WordPress.org plugins, and Marketplace extensions whose developers opt in. Teams can pin stubs to the minimum extension version they support, which helps PHPStan check calls against the versions their code is meant to work with.
What WooCommerce PHP stubs change for developers
WooCommerce says its engineering team uses PHPStan alongside other tools for testing, linting, and static analysis. But PHPStan cannot verify a call to a class or method it does not know. When integration code depends on another extension, developers have had to skip or baseline those checks, or maintain stubs by hand.
That creates two specific problems, according to the announcement. Hand-written stubs can become outdated, and checking against only the latest extension version can miss compatibility problems for sites running an older supported version. The new package is intended to make those calls visible to analysis and give developers a way to select the version they need to check.
In practice, this means a team building a plugin or theme that integrates with Woo extensions can add the stubs to its analysis setup instead of installing every integration partner’s plugin there. It does not mean the package tests runtime behavior or guarantees compatibility. It gives static analysis descriptions of functions, classes, interfaces, traits, enums, and constants so the analyzer can inspect calls against them.
What the public package contains
The initial package includes the first release of each of the newest 10 minor versions, using the x.y.0 release, as well as the newest release. A patch release remains available only while it is the newest release. This makes version selection a practical part of setup, rather than a detail to leave to chance.
Coverage includes Woo-owned paid plugins from the WooCommerce Marketplace and free Woo-owned plugins from WordPress.org. Marketplace extensions from other developers can be included when their developers opt in. The package also has a supplement for WooCommerce internals that the separate WooCommerce stubs package skips; it selects the matching supplement automatically.
The generator creates the stubs from each extension’s release. WooCommerce says new stubs publish automatically, with paid plugins updated within an hour and free plugins updated daily. Those schedules are useful context for teams deciding how to keep their analysis dependencies current, but the post does not describe them as a substitute for choosing the minimum version a project supports.
How to add the stubs to a project
WooCommerce’s instructions use Composer and PHPStan configuration. The package is installed as a development dependency alongside the WooCommerce stubs package. Developers then include the stub files for the extensions their code calls.
- Require
woocommerce/php-stubs:dev-trunkandphp-stubs/woocommerce-stubsas development dependencies. - Add each integrated plugin’s stub file to
phpstan.neon.dist. - Pin a plugin to its minimum supported x.y.0 version, or use its
latest.neonfile when the project does not declare a minimum. - Include the WooCommerce internals supplement if needed; it matches the installed WooCommerce stubs automatically.
The minimum-version setting deserves attention. If a project supports an older release but analyzes only against the newest one, PHPStan may accept a method call that the older release does not have. WooCommerce specifically recommends pinning the stub version alongside the project’s minimum version requirement.
There is one further configuration detail for code that checks plugin versions. A stub defines a version constant using the value from one release. WooCommerce says developers should add such constants to PHPStan’s dynamicConstantNames configuration so version comparisons are not treated as fixed values.
The stubs are plain PHP. The post says Phan, Psalm, and IDEs can also read them, and points developers to the package README for the files to load. That gives teams using those tools a possible route to reuse the generated descriptions, though the post’s setup example focuses on PHPStan.
How extension developers can opt in
Third-party developers with Marketplace extensions can request public stubs by adding Woo Stubs: public to the main plugin file header in their next release. WooCommerce says the stubs for that release will then be generated and published.
For a WordPress.org plugin that is not already included, the announcement directs developers to open an issue in the package repository and provide information about the plugin and the integration they want to check. That leaves inclusion as an opt-in or requested path for extensions outside WooCommerce’s own plugin set.
This approach is useful because the value of the package depends on the integrations a project actually uses. Adding every available stub is not the stated setup: include the extensions called by your code, then set their versions to match your support policy.
FAQ
Do the stubs remove the need to install every Woo extension?
For static analysis of supported integrations, WooCommerce says developers can use the stubs without installing every extension in the analysis environment. The package supplies descriptions for PHPStan to check, rather than the extensions’ runtime code.
Which extension versions should a project configure?
Pin each extension to the minimum x.y.0 version the project supports. If there is no declared minimum, WooCommerce’s example uses the extension’s latest.neon file.
Can third-party extensions be included?
Marketplace developers can opt in by adding Woo Stubs: public to the main plugin file header in a future release. For another WordPress.org plugin, the post says to open an issue with details about the plugin and the integration to check.
Next step: add the package to a development branch and configure stubs for the extensions your code actually supports, pinning each to its minimum version.