Skip to main content

Overview

WooCommerce uses a monorepo structure, meaning multiple related packages, plugins, and tools are maintained in a single repository. This approach enables code sharing, consistent versioning, and streamlined development workflows.

Top-Level Structure

plugins/

Contains WordPress plugins related to WooCommerce:
  • woocommerce/ - The core WooCommerce plugin
  • woocommerce-beta-tester/ - Beta testing tool

packages/

Shared code organized into reusable packages:

packages/js/

Over 30 JavaScript/TypeScript packages for building WooCommerce interfaces:
Packages prefixed with internal- are not intended for public use and may change without notice.

packages/php/

PHP packages for WooCommerce functionality:

tools/

Development and release tools:

WooCommerce Core Plugin Structure

The main WooCommerce plugin at plugins/woocommerce/ has a specific organization:

src/ - Modern PHP Code

The src/ directory contains modern PHP code following PSR-4 autoloading standards:
Namespace Convention: Automattic\WooCommerce\
  • Public API classes go directly in src/
  • Internal implementation goes in src/Internal/

includes/ - Legacy Code

The includes/ directory contains legacy WordPress-style code:
Avoid modifying code in includes/ unless necessary. New functionality should be added to src/ using modern patterns.

client/ - React Admin

React-based admin interface:

templates/

PHP template files for the storefront:
Themes can override these templates by copying them to your-theme/woocommerce/.

tests/

Test suites for WooCommerce:

Configuration Files

Root Configuration

Defines workspace packages:

Plugin Configuration

Each plugin has its own configuration:
  • package.json - npm scripts and dependencies
  • composer.json - PHP dependencies
  • .wp-env.json - WordPress environment config
  • phpunit.xml - PHPUnit test configuration

Code Organization Principles

Modern vs Legacy

Modern Code (src/)

  • PSR-4 autoloading
  • Strict types
  • Dependency injection
  • Unit testable
  • Type hints

Legacy Code (includes/)

  • WordPress hooks
  • Global functions
  • Singletons
  • Direct instantiation
  • WordPress coding standards

When to Use Each

Use src/ for:
  • New features and functionality
  • Complex business logic
  • Code requiring unit tests
  • Internal services and utilities
Use includes/ for:
  • Maintaining existing functionality
  • WordPress-specific hooks
  • Template functions
  • Backward compatibility

Finding Your Way Around

Common Tasks

Product classes:
  • Abstract: includes/abstracts/abstract-wc-product.php
  • Simple: includes/class-wc-product-simple.php
  • Variable: includes/class-wc-product-variable.php
Order classes:
  • Abstract: includes/abstracts/abstract-wc-order.php
  • Order: includes/class-wc-order.php
  • Order Item: includes/class-wc-order-item.php
REST API:
  • V3 Controllers: src/Admin/API/ and includes/rest-api/Controllers/Version3/
  • V2 Controllers: includes/rest-api/Controllers/Version2/
Admin Features:
  • Modern admin: src/Admin/
  • React UI: client/admin/
  • Legacy admin: includes/admin/
Frontend Templates:
  • All templates: templates/
  • Template functions: includes/wc-template-functions.php
  • Template hooks: includes/wc-template-hooks.php

Package Dependencies

Packages can depend on each other. View dependencies in package.json:
workspace:* references packages within the monorepo.

Building and Development

Building Specific Packages

Running Tests

Next Steps

Core Concepts

Learn about WooCommerce architecture

Monorepo Workflow

Master monorepo development

Modern vs Legacy

Understand code organization

Extension Development

Start building extensions