Skip to main content
WooCommerce follows strict coding standards to ensure code quality, consistency, and maintainability across the entire codebase. This guide covers both PHP and JavaScript standards.

PHP Coding Standards

WooCommerce follows the WordPress Coding Standards for PHP code, with additional WooCommerce-specific requirements.

PHP Standards Overview

WordPress Standards

Base standards from WordPress core

WooCommerce Core

Additional WooCommerce-specific rules

PSR-4 Autoloading

Modern code in src/ directory

PHP Compatibility

Support for PHP 7.4+

Modern vs Legacy Code Architecture

WooCommerce has two distinct code styles based on directory structure:

PHP Linting Commands

Run these commands from the WooCommerce plugin directory:
The pre-commit hook will automatically run linting on staged PHP files before allowing a commit.

PHPStan Static Analysis

Before committing PHP changes, run PHPStan to catch type errors:
PHPStan failures often indicate the need to update the baseline file (phpstan-baseline.neon). If your fix resolves a previously baselined error, remove the corresponding entry from the baseline.

PHP Configuration (phpcs.xml)

The root phpcs.xml file defines the PHP_CodeSniffer rules:
phpcs.xml

PHP Code Requirements

1

Namespace Requirements

All modern code must use the Automattic\WooCommerce namespace:
2

Dependency Injection

Classes in src/ must use dependency injection via init() method:
3

Documentation

All classes and methods must have proper DocBlocks:
4

Type Hints

Use PHP type hints for all parameters and return values (PHP 7.4+):

JavaScript Coding Standards

JavaScript code follows the WordPress JavaScript coding standards via ESLint.

JavaScript Linting

ESLint Configuration

The root .eslintrc.js extends WooCommerce ESLint plugin:
.eslintrc.js

JavaScript Code Requirements

Code Review Requirements

Before submitting a pull request, ensure your code meets these requirements:

Pre-Commit Checklist

  • All PHP code passes lint:php:changes without errors
  • All JavaScript code passes lint:lang:js without errors
  • PHPStan analysis passes on modified PHP files
  • Code follows WordPress and WooCommerce coding standards
  • All functions and classes have proper documentation
  • Type hints are used for all parameters and return values (PHP)
  • No hardcoded text strings (use i18n functions)
  • Security best practices are followed (nonce verification, sanitization, escaping)
  • Code supports minimum PHP (7.4+) and WordPress (5.2+) versions

Pre-Commit Hooks

The repository includes Husky pre-commit hooks that automatically run:
package.json (lint-staged)
The hooks will automatically fix many issues and prevent commits that don’t meet standards.

Editor Configuration

EditorConfig

Use EditorConfig to automatically configure your editor:
.editorconfig
Always use LF (Unix) line endings, never CRLF (Windows). This is critical for Git consistency.

Common Standards Issues

Text Domain

All translatable strings must use the woocommerce text domain:

File Naming

Escaping and Sanitization

Next Steps

Testing

Learn about testing requirements and commands

Git Workflow

Follow our Git workflow for contributions