@ai-kits/wp-ag-kit 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +12 -14
  2. package/STRUCTURE.md +9 -7
  3. package/agents/woocommerce-expert.md +32 -0
  4. package/agents/wordpress-expert.md +4 -2
  5. package/package.json +5 -3
  6. package/skills/woocommerce/SKILL.md +54 -0
  7. package/skills/woocommerce/references/backend-dev-guide.md +44 -0
  8. package/skills/woocommerce/references/code-entities.md +186 -0
  9. package/skills/woocommerce/references/code-quality.md +273 -0
  10. package/skills/woocommerce/references/code-review-guide.md +71 -0
  11. package/skills/woocommerce/references/coding-conventions.md +182 -0
  12. package/skills/woocommerce/references/copy-guidelines-guide.md +17 -0
  13. package/skills/woocommerce/references/data-integrity.md +164 -0
  14. package/skills/woocommerce/references/dependency-injection.md +102 -0
  15. package/skills/woocommerce/references/dev-cycle-guide.md +32 -0
  16. package/skills/woocommerce/references/file-entities.md +73 -0
  17. package/skills/woocommerce/references/hooks.md +87 -0
  18. package/skills/woocommerce/references/js-i18n-patterns.md +298 -0
  19. package/skills/woocommerce/references/markdown-guide.md +358 -0
  20. package/skills/woocommerce/references/markdown-linting.md +202 -0
  21. package/skills/woocommerce/references/php-i18n-patterns.md +83 -0
  22. package/skills/woocommerce/references/php-linting-patterns.md +304 -0
  23. package/skills/woocommerce/references/running-tests.md +249 -0
  24. package/skills/woocommerce/references/security-patterns.md +109 -0
  25. package/skills/woocommerce/references/sentence-case.md +177 -0
  26. package/skills/woocommerce/references/type-annotations.md +161 -0
  27. package/skills/woocommerce/references/unit-tests.md +362 -0
  28. package/skills/woocommerce/references/woocommerce-global-objects.md +89 -0
@@ -0,0 +1,89 @@
1
+ # WooCommerce Global Objects and Functions
2
+
3
+ This guide covers the correct way to access and interact with core WooCommerce objects.
4
+
5
+ ## Core Objects
6
+
7
+ ### Products
8
+
9
+ Always use `wc_get_product()` to retrieve product objects.
10
+
11
+ ```php
12
+ // From ID
13
+ $product = wc_get_product( $product_id );
14
+
15
+ // From global $post (only in loop)
16
+ global $post;
17
+ $product = wc_get_product( $post->ID );
18
+ ```
19
+
20
+ ### Orders
21
+
22
+ Always use `wc_get_order()`.
23
+
24
+ ```php
25
+ $order = wc_get_order( $order_id );
26
+ ```
27
+
28
+ ### Cart
29
+
30
+ Use the `WC()` global to access the cart session.
31
+
32
+ ```php
33
+ // Get cart total
34
+ $total = WC()->cart->get_total();
35
+
36
+ // Add to cart
37
+ WC()->cart->add_to_cart( $product_id, $quantity );
38
+ ```
39
+
40
+ ## The `WC()` Global Helper
41
+
42
+ Prefer the `WC()` function over global variables like `$woocommerce`.
43
+
44
+ ```php
45
+ // ✅ GOOD
46
+ WC()->session->get( 'key' );
47
+ WC()->mailer();
48
+
49
+ // ❌ AVOID
50
+ global $woocommerce;
51
+ $woocommerce->session->get( 'key' );
52
+ ```
53
+
54
+ ## Correct Method Usage (Modern WC)
55
+
56
+ ### Getting Data
57
+
58
+ Always use getters. Never access properties directly.
59
+
60
+ ```php
61
+ // ✅ GOOD
62
+ $sku = $product->get_sku();
63
+ $price = $product->get_price();
64
+
65
+ // ❌ WRONG
66
+ $sku = $product->sku;
67
+ ```
68
+
69
+ ### Setting Data
70
+
71
+ Always use setters and then call `save()`.
72
+
73
+ ```php
74
+ $product->set_sku( 'NEW-SKU-123' );
75
+ $product->set_regular_price( '19.99' );
76
+ $product->save();
77
+ ```
78
+
79
+ ## Common Helper Functions
80
+
81
+ - `wc_get_template()`: For loading templates with overrides support.
82
+ - `wc_price()`: For formatting prices with currency symbols.
83
+ - `wc_get_endpoint_url()`: For linking to My Account or Checkout endpoints.
84
+ - `wc_add_notice()`: For showing feedback messages to users.
85
+ - `wc_get_cart_url()`: For getting the cart page link.
86
+
87
+ ```php
88
+ wc_add_notice( __( 'Item added to your cart.', 'woocommerce' ), 'success' );
89
+ ```