From woocommerce-commerce
Applies PHP design patterns—Singleton, Factory, Strategy, Observer, Repository, Decorator, DI—with WooCommerce examples for plugin structure and business logic.
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin woocommerce-commerceThis skill is limited to using the following tools:
**Fetch live docs**: Web-search `php design patterns modern` for current pattern implementations. Reference `https://refactoring.guru/design-patterns/php` for comprehensive examples.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
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.