/woocommerce-commerce:php-patternsfrom woocommerce-commerce
Applies PHP design patterns (Singleton, Factory, Strategy, Observer, Repository, Decorator, DI) to WooCommerce extension code and complex business logic.
Ships in woocommerce-commerce. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Fetch live docs: Web-search php design patterns modern for current pattern implementations. Reference https://refactoring.guru/design-patterns/php for comprehensive examples.
Ensures only one instance of a class exists. Common in WordPress/WooCommerce plugins as the main plugin class.
WC() returns the single WooCommerce instance. Extension main classes typically follow:
__construct(), private __clone(), private __wakeup()instance() methodfunction my_extension() { return My_Extension::instance(); })Plugin entry points only. Avoid for everything else — singletons are hard to test and create hidden dependencies.
Creates objects without specifying the exact class. Decouples object creation from usage.
WC_Product_Factory resolves product type to correct class:
wc_get_product( $id ) — factory method returns WC_Product_Simple, WC_Product_Variable, etc.woocommerce_product_class hookDefine a factory method or class that maps identifiers to concrete classes. Use for: product types, payment gateway selection, shipping method resolution.
Defines a family of interchangeable algorithms. Client code works with the interface, not the implementation.
WC_Payment_Gateway, swappable at checkoutWC_Shipping_Method, configurable per zoneDefine an interface/abstract class. Create concrete implementations. Select the strategy at runtime based on configuration or context.
Objects subscribe to events and get notified when they occur. Loose coupling between event producers and consumers.
WordPress hooks ARE the Observer pattern:
do_action() / apply_filters() — notify observersadd_action() / add_filter() — subscribeUse WordPress hooks for WooCommerce extensions. For internal events within your plugin, consider firing custom actions: do_action( 'my_plugin_after_process', $data ).
Mediates between the domain layer and data mapping layer. Provides collection-like access to data.
While WooCommerce uses Data Stores rather than formal Repositories, the concept is similar:
wc_get_orders( $args ) — query-based data accesswc_get_products( $args ) — product collection accessCreate a class that provides methods like find_by_id(), find_all(), save(), delete(). Internally use wc_get_orders() or custom queries.
Adds behavior to objects dynamically by wrapping them. Each decorator adds one concern.
Filters act as decorators:
apply_filters( 'woocommerce_product_get_price', $price, $product ) — each filter wraps/modifies the valueCreate wrapper classes that implement the same interface as the wrapped object. Delegate most calls, add behavior where needed.
Objects receive their dependencies through constructors or setters rather than creating them internally.
WordPress doesn't have a built-in DI container, but you can practice DI:
WC(), $wpdb, etc. where possibleclass OrderProcessor {
public function __construct(
private readonly PaymentGateway $gateway,
private readonly ShippingCalculator $shipping,
) {}
}
A registry that provides access to services. Less preferred than DI, but practical in WordPress.
WC()->payment_gateways() — access payment gateways registryWC()->shipping() — access shipping methods registryWC()->cart — access cart instanceDefines the skeleton of an algorithm in a base class, letting subclasses override specific steps.
WC_Payment_Gateway — defines the gateway lifecycle; subclasses implement process_payment(), init_form_fields()WC_Shipping_Method — defines shipping lifecycle; subclasses implement calculate_shipping()Fetch design pattern references for current PHP implementations and WooCommerce core examples before implementing.
What SKILL.md sets; muted values are Claude Code's defaults
20 skills in this plugin
/php-modernWrite modern PHP 8.x code — typed properties, enums, readonly classes, match expressions, named arguments, union/intersection types, fibers, attributes, and constructor promotion. Use when writing PHP for WooCommerce or any PHP 8.x project./php-testingWrite PHP tests with PHPUnit — unit tests, mocking, data providers, assertions, test doubles, and TDD workflow. Use when writing tests for WooCommerce extensions or PHP projects./woo-adminBuild WooCommerce admin interfaces — settings pages, admin menus, product data tabs/panels, order meta boxes, WooCommerce Admin (React analytics), and reports. Use when creating admin-facing configuration or display pages.npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin woocommerce-commerceOther plugins' skills for the same job