$npx -y skills add mralaminahamed/wp-dev-skills --skill wp-woocommerceUse when building, extending, or debugging a WooCommerce plugin — custom product types, payment gateways (WC_Payment_Gateway, process_payment(), process_refund()), shipping methods (WC_Shipping_Method, calculate_shipping()), CRUD via WC_Product / WC_Order / WC_Customer (wc_get_pr
| 1 | # WooCommerce Extension Development |
| 2 | |
| 3 | > **Model note:** Complex — payment gateways, HPOS compatibility, and block cart/checkout require multi-file reasoning. Use `sonnet` or `opus`. `haiku` for isolated CRUD or hook lookups only. |
| 4 | |
| 5 | Guide for building WooCommerce extensions: custom product types, payment gateways, hooks, CRUD, REST, and admin UI. Assumes the host plugin passes the `wp-plugin-audit` baseline and the official `wp-plugin-development` security conventions. |
| 6 | |
| 7 | ## When to use |
| 8 | |
| 9 | - "Add a custom product type", "create a payment gateway", "add a shipping method". |
| 10 | - "Extend the WooCommerce REST API", "add fields to WC orders/products". |
| 11 | - "Build a WooCommerce admin tab", "add product meta", "custom checkout field". |
| 12 | - "Hook into WC cart/checkout", "add a fee", "apply a discount programmatically". |
| 13 | - "Debug WooCommerce order status flow", "fix a WC hook not firing". |
| 14 | |
| 15 | **Not for:** General WordPress plugin architecture — use `wp-plugin-development`. PHPStan types for WC — use `wp-phpstan-stubs` to scaffold WC stubs. |
| 16 | |
| 17 | ## Method |
| 18 | |
| 19 | ### 1. Identify extension point category |
| 20 | |
| 21 | Determine which WC subsystem applies before writing code: |
| 22 | |
| 23 | | Goal | Subsystem | |
| 24 | |---|---| |
| 25 | | Custom product type | `WC_Product` subclass + `product_type_query` filter | |
| 26 | | Payment gateway | `WC_Payment_Gateway` subclass + `woocommerce_payment_gateways` filter | |
| 27 | | Shipping method | `WC_Shipping_Method` subclass + `woocommerce_shipping_methods` filter | |
| 28 | | Custom order status | `wc_register_order_status` + `wc_order_statuses` filter | |
| 29 | | Cart/checkout field | `woocommerce_checkout_fields` filter or block integration API | |
| 30 | | Admin product tab | `woocommerce_product_data_tabs` + `woocommerce_product_data_panels` | |
| 31 | | Order list column | `manage_edit-shop_order_columns` + `manage_shop_order_posts_custom_column` | |
| 32 | | REST API extension | `woocommerce_rest_*` hooks or custom endpoint on `WC_REST_Controller` | |
| 33 | |
| 34 | ### 2. CRUD — use WC classes, not direct `$wpdb` |
| 35 | |
| 36 | Always use WC CRUD methods; they fire the correct hooks and invalidate caches. |
| 37 | |
| 38 | ```php |
| 39 | // Orders |
| 40 | $order = wc_create_order( [ 'status' => 'pending', 'customer_id' => $user_id ] ); |
| 41 | $order->add_product( wc_get_product( $product_id ), 1 ); |
| 42 | $order->calculate_totals(); |
| 43 | $order->save(); |
| 44 | |
| 45 | // Products |
| 46 | $product = new WC_Product_Simple(); |
| 47 | $product->set_name( 'My Product' ); |
| 48 | $product->set_regular_price( '19.99' ); |
| 49 | $product->set_status( 'publish' ); |
| 50 | $product->save(); |
| 51 | |
| 52 | // Reading |
| 53 | $order = wc_get_order( $order_id ); // returns WC_Order or false |
| 54 | $product = wc_get_product( $product_id ); // returns WC_Product subclass or false |
| 55 | ``` |
| 56 | |
| 57 | For meta, use `$order->get_meta()` / `$order->update_meta_data()` + `$order->save()` — never `update_post_meta()` on orders (breaks HPOS). |
| 58 | |
| 59 | ### 3. HPOS compatibility |
| 60 | |
| 61 | WooCommerce 8.2+ ships **High-Performance Order Storage** (HPOS). Extensions must declare compatibility or they're disabled in HPOS stores. |
| 62 | |
| 63 | ```php |
| 64 | add_action( 'before_woocommerce_init', function() { |
| 65 | if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 66 | \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( |
| 67 | 'custom_order_tables', __FILE__, true |
| 68 | ); |
| 69 | } |
| 70 | } ); |
| 71 | ``` |
| 72 | |
| 73 | Rules under HPOS: |
| 74 | - Never read/write orders via `get_post_meta()` / `update_post_meta()` — use `WC_Order` getters/setters. |
| 75 | - Never q |