fluentcart-developer 2.3.0 → 2.3.2

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 (49) hide show
  1. package/README.md +59 -59
  2. package/dist/cards/fluentcart/tools.d.ts.map +1 -1
  3. package/dist/cards/fluentcart/tools.js +160 -12
  4. package/dist/cards/fluentcart/tools.js.map +1 -1
  5. package/dist/skills/fluentcart-developer/.claude-plugin/plugin.json +12 -12
  6. package/dist/skills/fluentcart-developer/.mcp.json +11 -11
  7. package/dist/skills/fluentcart-developer/examples/fluentcart-starter-child-theme/fluent-cart/checkout.php +32 -32
  8. package/dist/skills/fluentcart-developer/examples/fluentcart-starter-child-theme/functions.php +40 -40
  9. package/dist/skills/fluentcart-developer/examples/sample-fee-surcharge-plugin/fluentcart-fee-surcharge.php +38 -38
  10. package/dist/skills/fluentcart-developer/references/action-hooks-cart-checkout.md +1355 -1355
  11. package/dist/skills/fluentcart-developer/references/action-hooks-customers-users.md +266 -266
  12. package/dist/skills/fluentcart-developer/references/action-hooks-licenses.md +855 -855
  13. package/dist/skills/fluentcart-developer/references/action-hooks-orders.md +631 -631
  14. package/dist/skills/fluentcart-developer/references/action-hooks-payments-integrations.md +963 -963
  15. package/dist/skills/fluentcart-developer/references/action-hooks-products-coupons.md +585 -585
  16. package/dist/skills/fluentcart-developer/references/action-hooks-subscriptions.md +661 -661
  17. package/dist/skills/fluentcart-developer/references/database-models-query-builder.md +194 -194
  18. package/dist/skills/fluentcart-developer/references/database-models-reference.md +604 -604
  19. package/dist/skills/fluentcart-developer/references/engineering-notes.md +154 -154
  20. package/dist/skills/fluentcart-developer/references/fee-system-guide.md +449 -449
  21. package/dist/skills/fluentcart-developer/references/filter-hooks-cart-checkout.md +1202 -1202
  22. package/dist/skills/fluentcart-developer/references/filter-hooks-integrations-advanced.md +1598 -1598
  23. package/dist/skills/fluentcart-developer/references/filter-hooks-products-pricing.md +628 -628
  24. package/dist/skills/fluentcart-developer/references/filter-hooks-settings-configuration.md +1177 -1177
  25. package/dist/skills/fluentcart-developer/references/fluentcart-developer-guide.md +154 -154
  26. package/dist/skills/fluentcart-developer/references/ghost-product-selling.md +458 -458
  27. package/dist/skills/fluentcart-developer/references/modules-and-extensions-reference.md +224 -224
  28. package/dist/skills/fluentcart-developer/references/payment-gateway-integration.md +761 -761
  29. package/dist/skills/fluentcart-developer/references/rest-api-customer-profile.md +190 -190
  30. package/dist/skills/fluentcart-developer/references/rest-api-customers.md +1121 -1121
  31. package/dist/skills/fluentcart-developer/references/rest-api-dashboard-utilities.md +219 -219
  32. package/dist/skills/fluentcart-developer/references/rest-api-email-notifications.md +619 -619
  33. package/dist/skills/fluentcart-developer/references/rest-api-files.md +290 -290
  34. package/dist/skills/fluentcart-developer/references/rest-api-integrations.md +324 -324
  35. package/dist/skills/fluentcart-developer/references/rest-api-labels-attributes.md +321 -321
  36. package/dist/skills/fluentcart-developer/references/rest-api-order-bumps.md +200 -200
  37. package/dist/skills/fluentcart-developer/references/rest-api-overview.md +131 -131
  38. package/dist/skills/fluentcart-developer/references/rest-api-public-shop.md +172 -172
  39. package/dist/skills/fluentcart-developer/references/rest-api-reference.md +552 -552
  40. package/dist/skills/fluentcart-developer/references/rest-api-reports.md +377 -377
  41. package/dist/skills/fluentcart-developer/references/rest-api-roles-permissions.md +147 -147
  42. package/dist/skills/fluentcart-developer/references/rest-api-settings.md +528 -528
  43. package/dist/skills/fluentcart-developer/references/rest-api-shipping.md +799 -799
  44. package/dist/skills/fluentcart-developer/references/rest-api-tax.md +356 -356
  45. package/dist/skills/fluentcart-developer/references/subscription-customization.md +197 -197
  46. package/dist/skills/fluentcart-developer/scripts/cli.js +1 -1
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/package.json +65 -65
@@ -1,1121 +1,1121 @@
1
- # Customers API
2
-
3
- Manage customer records including creating customers, managing addresses, associating WordPress users, and viewing customer order history.
4
-
5
- **Base URL:** `https://your-site.com/wp-json/fluent-cart/v2/customers`
6
-
7
- **Policy:** `CustomerPolicy`
8
-
9
- > All monetary values are in cents (e.g., `$10.00` = `1000`).
10
-
11
- ---
12
-
13
- ## Endpoints Overview
14
-
15
- | Method | Endpoint | Description |
16
- |--------|----------|-------------|
17
- | **Customer CRUD** | | |
18
- | GET | `/customers` | List Customers |
19
- | POST | `/customers` | Create Customer |
20
- | GET | `/customers/{customerId}` | Get Customer |
21
- | PUT | `/customers/{customerId}` | Update Customer |
22
- | PUT | `/customers/{customerId}/additional-info` | Update Additional Info (Labels) |
23
- | POST | `/customers/do-bulk-action` | Bulk Actions |
24
- | **Stats & Orders** | | |
25
- | GET | `/customers/get-stats/{customer}` | Get Customer Stats |
26
- | GET | `/customers/{customerId}/orders` | Get Customer Orders |
27
- | GET | `/customers/{customerId}/order` | Find Customer Order |
28
- | POST | `/customers/{customerId}/recalculate-ltv` | Recalculate Lifetime Value |
29
- | **Address Management** | | |
30
- | GET | `/customers/{customerId}/address` | Get Customer Addresses |
31
- | POST | `/customers/{customerId}/address` | Create Address |
32
- | PUT | `/customers/{customerId}/address` | Update Address |
33
- | DELETE | `/customers/{customerId}/address` | Delete Address |
34
- | POST | `/customers/{customerId}/address/make-primary` | Set Primary Address |
35
- | **User Association** | | |
36
- | GET | `/customers/attachable-user` | Get Attachable Users |
37
- | POST | `/customers/{customerId}/attachable-user` | Attach WordPress User |
38
- | POST | `/customers/{customerId}/detach-user` | Detach WordPress User |
39
-
40
- ---
41
-
42
- ## Customer CRUD
43
-
44
- ### List Customers
45
-
46
- `GET /fluent-cart/v2/customers`
47
-
48
- Retrieve a paginated list of customers with support for searching, sorting, and advanced filtering.
49
-
50
- **Permission:** `customers/view`
51
-
52
- #### Parameters
53
-
54
- | Parameter | Type | Location | Required | Description |
55
- |-----------|------|----------|----------|-------------|
56
- | `search` | string | query | No | Search by customer name, email, or ID. Supports operator syntax (e.g., `id=5`, `ltv>1000`). |
57
- | `per_page` | integer | query | No | Number of items per page (1-199, default: 10) |
58
- | `page` | integer | query | No | Page number for pagination |
59
- | `sort_by` | string | query | No | Column to sort by. Must be a fillable field on the Customer model (default: `id`) |
60
- | `sort_type` | string | query | No | Sort direction: `asc` or `desc` (default: `desc`) |
61
- | `filter_type` | string | query | No | Filter mode: `simple` or `advanced` (default: `simple`) |
62
- | `advanced_filters` | string (JSON) | query | No | JSON-encoded array of advanced filter groups (Pro only). Supports filtering by order items, purchase count, purchase dates, customer name, email, LTV, and labels. |
63
- | `with` | array | query | No | Relationships to eager-load (e.g., `orders`, `labels`, `billing_address`, `shipping_address`) |
64
- | `select` | string/array | query | No | Comma-separated column names or array of columns to select |
65
- | `include_ids` | string/array | query | No | Comma-separated IDs or array of IDs that must be included in results |
66
- | `active_view` | string | query | No | Active tab/view filter |
67
- | `user_tz` | string | query | No | User timezone for date filter conversion |
68
-
69
- #### Response
70
-
71
- ```json
72
- {
73
- "customers": {
74
- "total": 150,
75
- "per_page": 10,
76
- "current_page": 1,
77
- "last_page": 15,
78
- "data": [
79
- {
80
- "id": 1,
81
- "user_id": 5,
82
- "contact_id": null,
83
- "email": "john@example.com",
84
- "first_name": "John",
85
- "last_name": "Doe",
86
- "status": "active",
87
- "purchase_value": { ... },
88
- "purchase_count": 3,
89
- "ltv": 15000,
90
- "first_purchase_date": "2025-01-15 10:30:00",
91
- "last_purchase_date": "2025-06-20 14:00:00",
92
- "aov": 5000,
93
- "notes": "",
94
- "uuid": "a1b2c3d4...",
95
- "country": "US",
96
- "city": "New York",
97
- "state": "NY",
98
- "postcode": "10001",
99
- "created_at": "2025-01-10 08:00:00",
100
- "updated_at": "2025-06-20 14:00:00",
101
- "full_name": "John Doe",
102
- "photo": "https://gravatar.com/avatar/...",
103
- "country_name": "United States",
104
- "formatted_address": { ... },
105
- "user_link": "https://example.com/wp-admin/user-edit.php?user_id=5"
106
- }
107
- ]
108
- }
109
- }
110
- ```
111
-
112
- #### Example
113
-
114
- ```bash
115
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers?per_page=20&search=john&sort_by=created_at&sort_type=desc" \
116
- -u "username:app_password"
117
- ```
118
-
119
- ---
120
-
121
- ### Create Customer
122
-
123
- `POST /fluent-cart/v2/customers`
124
-
125
- Create a new customer record. Automatically links to an existing WordPress user if a matching email is found.
126
-
127
- **Permission:** `customers/manage`
128
-
129
- #### Parameters
130
-
131
- | Parameter | Type | Location | Required | Description |
132
- |-----------|------|----------|----------|-------------|
133
- | `email` | string | body | Yes | Customer email address. Must be unique and valid. Max 255 characters. |
134
- | `first_name` | string | body | Conditional | Customer first name. Required when store is not configured for full name mode. Max 255 characters. |
135
- | `last_name` | string | body | No | Customer last name. Max 255 characters. |
136
- | `full_name` | string | body | Conditional | Customer full name. Required when store is configured for full name mode. Max 255 characters. Automatically split into `first_name` and `last_name`. |
137
- | `city` | string | body | No | Customer city |
138
- | `state` | string | body | No | Customer state/province code |
139
- | `postcode` | string | body | No | Customer postal/zip code |
140
- | `country` | string | body | No | Customer country code (e.g., `US`, `GB`) |
141
- | `notes` | string | body | No | Internal notes about the customer |
142
- | `status` | string | body | No | Customer status |
143
- | `user_id` | integer | body | No | WordPress user ID to associate |
144
- | `wp_user` | string | body | No | Set to `yes` to create a new WordPress user account for this customer |
145
- | `aov` | string | body | No | Average order value |
146
- | `user_url` | string | body | No | Customer website URL |
147
-
148
- #### Response
149
-
150
- Success (200):
151
-
152
- ```json
153
- {
154
- "message": "Customer created successfully!",
155
- "data": {
156
- "id": 42,
157
- "user_id": null,
158
- "email": "jane@example.com",
159
- "first_name": "Jane",
160
- "last_name": "Smith",
161
- "status": "active",
162
- "purchase_value": [],
163
- "uuid": "e5f6g7h8...",
164
- "country": "US",
165
- "city": "Boston",
166
- "state": "MA",
167
- "postcode": "02101",
168
- "created_at": "2025-06-20 14:00:00",
169
- "updated_at": "2025-06-20 14:00:00"
170
- }
171
- }
172
- ```
173
-
174
- Error (email already exists):
175
-
176
- ```json
177
- {
178
- "code": 400,
179
- "message": "Customer already exists.",
180
- "data": ""
181
- }
182
- ```
183
-
184
- #### Example
185
-
186
- ```bash
187
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers" \
188
- -u "username:app_password" \
189
- -H "Content-Type: application/json" \
190
- -d '{
191
- "first_name": "Jane",
192
- "last_name": "Smith",
193
- "email": "jane@example.com",
194
- "country": "US",
195
- "city": "Boston",
196
- "state": "MA",
197
- "postcode": "02101",
198
- "wp_user": "yes"
199
- }'
200
- ```
201
-
202
- ---
203
-
204
- ### Get Customer
205
-
206
- `GET /fluent-cart/v2/customers/{customerId}`
207
-
208
- Retrieve a single customer by ID with optional eager-loaded relationships.
209
-
210
- **Permission:** `customers/view`
211
-
212
- #### Parameters
213
-
214
- | Parameter | Type | Location | Required | Description |
215
- |-----------|------|----------|----------|-------------|
216
- | `customerId` | integer | path | Yes | The customer ID |
217
- | `with` | array | query | No | Relationships to eager-load (e.g., `orders`, `labels`, `billing_address`, `shipping_address`, `subscriptions`, `wpUser`) |
218
- | `params[customer_only]` | string | query | No | Set to `yes` to return the customer without labels processing |
219
-
220
- #### Response
221
-
222
- ```json
223
- {
224
- "customer": {
225
- "id": 1,
226
- "user_id": 5,
227
- "contact_id": null,
228
- "email": "john@example.com",
229
- "first_name": "John",
230
- "last_name": "Doe",
231
- "status": "active",
232
- "purchase_value": { ... },
233
- "purchase_count": 3,
234
- "ltv": 15000,
235
- "first_purchase_date": "2025-01-15 10:30:00",
236
- "last_purchase_date": "2025-06-20 14:00:00",
237
- "aov": 5000,
238
- "notes": "",
239
- "uuid": "a1b2c3d4...",
240
- "country": "US",
241
- "city": "New York",
242
- "state": "NY",
243
- "postcode": "10001",
244
- "created_at": "2025-01-10 08:00:00",
245
- "updated_at": "2025-06-20 14:00:00",
246
- "full_name": "John Doe",
247
- "photo": "https://gravatar.com/avatar/...",
248
- "country_name": "United States",
249
- "formatted_address": {
250
- "country": "United States",
251
- "state": "New York",
252
- "city": "New York",
253
- "postcode": "10001",
254
- "first_name": "John",
255
- "last_name": "Doe",
256
- "full_name": "John Doe"
257
- },
258
- "user_link": "https://example.com/wp-admin/user-edit.php?user_id=5",
259
- "selected_labels": [1, 3, 7],
260
- "labels": [ ... ]
261
- }
262
- }
263
- ```
264
-
265
- Error (404):
266
-
267
- ```json
268
- {
269
- "message": "Customer not found",
270
- "back_text": "Back to Customer List",
271
- "back_url": "/customers"
272
- }
273
- ```
274
-
275
- #### Example
276
-
277
- ```bash
278
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1?with[]=labels&with[]=billing_address" \
279
- -u "username:app_password"
280
- ```
281
-
282
- ---
283
-
284
- ### Update Customer
285
-
286
- `PUT /fluent-cart/v2/customers/{customerId}`
287
-
288
- Update an existing customer. If the customer is linked to a WordPress user, the corresponding WP user profile is also updated.
289
-
290
- **Permission:** `customers/manage`
291
-
292
- #### Parameters
293
-
294
- | Parameter | Type | Location | Required | Description |
295
- |-----------|------|----------|----------|-------------|
296
- | `customerId` | integer | path | Yes | The customer ID |
297
- | `email` | string | body | Yes | Customer email address. Must be unique (excluding current customer). Max 255 characters. |
298
- | `first_name` | string | body | Conditional | Customer first name. Required when store is not configured for full name mode. Max 255 characters. |
299
- | `last_name` | string | body | No | Customer last name. Max 255 characters. |
300
- | `full_name` | string | body | Conditional | Customer full name. Required when store is configured for full name mode. Max 255 characters. |
301
- | `city` | string | body | No | Customer city |
302
- | `state` | string | body | No | Customer state/province code |
303
- | `postcode` | string | body | No | Customer postal/zip code |
304
- | `country` | string | body | No | Customer country code |
305
- | `notes` | string | body | No | Internal notes about the customer |
306
- | `status` | string | body | No | Customer status |
307
- | `user_id` | integer | body | No | WordPress user ID |
308
- | `aov` | string | body | No | Average order value |
309
- | `user_url` | string | body | No | Customer website URL |
310
- | `username` | string | body | No | Username |
311
- | `user_nicename` | string | body | No | User nicename |
312
- | `display_name` | string | body | No | Display name |
313
-
314
- #### Response
315
-
316
- Success (200):
317
-
318
- ```json
319
- {
320
- "message": "Customer updated successfully!",
321
- "data": {
322
- "id": 1,
323
- "user_id": 5,
324
- "email": "john@example.com",
325
- "first_name": "John",
326
- "last_name": "Doe",
327
- "status": "active"
328
- }
329
- }
330
- ```
331
-
332
- #### Example
333
-
334
- ```bash
335
- curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1" \
336
- -u "username:app_password" \
337
- -H "Content-Type: application/json" \
338
- -d '{
339
- "first_name": "John",
340
- "last_name": "Doe",
341
- "email": "john@example.com",
342
- "city": "San Francisco",
343
- "state": "CA",
344
- "country": "US"
345
- }'
346
- ```
347
-
348
- ---
349
-
350
- ### Update Additional Info (Labels)
351
-
352
- `PUT /fluent-cart/v2/customers/{customerId}/additional-info`
353
-
354
- Update a customer's labels/tags. Manages the label relationships for a customer by syncing provided label IDs with existing ones.
355
-
356
- **Permission:** `customers/manage`
357
-
358
- #### Parameters
359
-
360
- | Parameter | Type | Location | Required | Description |
361
- |-----------|------|----------|----------|-------------|
362
- | `customerId` | integer | path | Yes | The customer ID |
363
- | `labels` | array | body | Yes | Array of label IDs to assign to the customer. Existing labels not in this array will be removed. |
364
-
365
- #### Response
366
-
367
- Success (200):
368
-
369
- ```json
370
- {
371
- "message": "Customer updated successfully!",
372
- "data": { ... }
373
- }
374
- ```
375
-
376
- #### Example
377
-
378
- ```bash
379
- curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1/additional-info" \
380
- -u "username:app_password" \
381
- -H "Content-Type: application/json" \
382
- -d '{
383
- "labels": [1, 3, 7]
384
- }'
385
- ```
386
-
387
- ---
388
-
389
- ### Bulk Actions
390
-
391
- `POST /fluent-cart/v2/customers/do-bulk-action`
392
-
393
- Perform bulk operations on multiple customers such as deletion or status change.
394
-
395
- **Permission:** `customers/manage`
396
-
397
- #### Parameters
398
-
399
- | Parameter | Type | Location | Required | Description |
400
- |-----------|------|----------|----------|-------------|
401
- | `action` | string | body | Yes | The action to perform. Supported values: `delete_customers`, `change_customer_status` |
402
- | `customer_ids` | array | body | Yes | Array of customer IDs to act upon |
403
- | `new_status` | string | body | Conditional | Required when action is `change_customer_status`. The new status to apply to the selected customers. Must be a valid editable customer status. |
404
-
405
- #### Response
406
-
407
- Success (`delete_customers`):
408
-
409
- ```json
410
- {
411
- "message": "Selected Customers has been deleted permanently",
412
- "data": ""
413
- }
414
- ```
415
-
416
- Success (`change_customer_status`):
417
-
418
- ```json
419
- {
420
- "message": "Customer Status has been changed",
421
- "data": ""
422
- }
423
- ```
424
-
425
- Error (missing selection):
426
-
427
- ```json
428
- {
429
- "code": 403,
430
- "message": "Customers selection is required",
431
- "data": ""
432
- }
433
- ```
434
-
435
- #### Example
436
-
437
- ```bash
438
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/do-bulk-action" \
439
- -u "username:app_password" \
440
- -H "Content-Type: application/json" \
441
- -d '{
442
- "action": "change_customer_status",
443
- "customer_ids": [1, 2, 3],
444
- "new_status": "archived"
445
- }'
446
- ```
447
-
448
- ---
449
-
450
- ## Customer Stats & Orders
451
-
452
- ### Get Customer Stats
453
-
454
- `GET /fluent-cart/v2/customers/get-stats/{customer}`
455
-
456
- Retrieve widget/stats data for a specific customer. Results are extensible via the `fluent_cart/widgets/single_customer` filter.
457
-
458
- **Permission:** `customers/view`
459
-
460
- #### Parameters
461
-
462
- | Parameter | Type | Location | Required | Description |
463
- |-----------|------|----------|----------|-------------|
464
- | `customer` | integer | path | Yes | The customer ID |
465
-
466
- #### Response
467
-
468
- ```json
469
- {
470
- "widgets": []
471
- }
472
- ```
473
-
474
- The `widgets` array is populated by modules and extensions that hook into the `fluent_cart/widgets/single_customer` filter.
475
-
476
- #### Example
477
-
478
- ```bash
479
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/get-stats/1" \
480
- -u "username:app_password"
481
- ```
482
-
483
- ---
484
-
485
- ### Get Customer Orders
486
-
487
- `GET /fluent-cart/v2/customers/{customerId}/orders`
488
-
489
- Retrieve a paginated list of orders belonging to a specific customer. Supports the same filtering and sorting parameters as the main Orders list.
490
-
491
- **Permission:** `customers/view`
492
-
493
- #### Parameters
494
-
495
- | Parameter | Type | Location | Required | Description |
496
- |-----------|------|----------|----------|-------------|
497
- | `customerId` | integer | path | Yes | The customer ID |
498
- | `search` | string | query | No | Search orders by invoice number, customer name/email, or order item title |
499
- | `per_page` | integer | query | No | Number of items per page (1-199, default: 10) |
500
- | `page` | integer | query | No | Page number for pagination |
501
- | `sort_by` | string | query | No | Column to sort by (default: `id`) |
502
- | `sort_type` | string | query | No | Sort direction: `asc` or `desc` (default: `desc`) |
503
- | `filter_type` | string | query | No | Filter mode: `simple` or `advanced` (default: `simple`) |
504
- | `advanced_filters` | string (JSON) | query | No | JSON-encoded array of advanced filter groups |
505
- | `active_view` | string | query | No | Active tab filter (e.g., `on-hold`, `paid`, `completed`, `processing`) |
506
-
507
- #### Response
508
-
509
- ```json
510
- {
511
- "orders": {
512
- "total": 5,
513
- "per_page": 10,
514
- "current_page": 1,
515
- "last_page": 1,
516
- "data": [
517
- {
518
- "id": 101,
519
- "invoice_no": "FCT-0101",
520
- "customer_id": 1,
521
- "status": "completed",
522
- "payment_status": "paid",
523
- "total_amount": 5000
524
- }
525
- ]
526
- }
527
- }
528
- ```
529
-
530
- #### Example
531
-
532
- ```bash
533
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/orders?per_page=10&sort_by=created_at&sort_type=desc" \
534
- -u "username:app_password"
535
- ```
536
-
537
- ---
538
-
539
- ### Find Customer Order
540
-
541
- `GET /fluent-cart/v2/customers/{customerId}/order`
542
-
543
- Retrieve all orders for a customer with their filtered order items (line items) eager-loaded.
544
-
545
- **Permission:** `customers/view`
546
-
547
- #### Parameters
548
-
549
- | Parameter | Type | Location | Required | Description |
550
- |-----------|------|----------|----------|-------------|
551
- | `customerId` | integer | path | Yes | The customer ID |
552
-
553
- #### Response
554
-
555
- ```json
556
- {
557
- "data": {
558
- "data": [
559
- {
560
- "id": 101,
561
- "customer_id": 1,
562
- "invoice_no": "FCT-0101",
563
- "total_amount": 5000,
564
- "filtered_order_items": [
565
- {
566
- "id": 1,
567
- "order_id": 101,
568
- "title": "Product Name",
569
- "quantity": 2,
570
- "unit_price": 2500
571
- }
572
- ]
573
- }
574
- ]
575
- }
576
- }
577
- ```
578
-
579
- #### Example
580
-
581
- ```bash
582
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/order" \
583
- -u "username:app_password"
584
- ```
585
-
586
- ---
587
-
588
- ### Recalculate Lifetime Value
589
-
590
- `POST /fluent-cart/v2/customers/{customerId}/recalculate-ltv`
591
-
592
- Recalculate a customer's lifetime value (LTV) by summing net payments from all successful orders. Also updates `purchase_count`, `first_purchase_date`, `last_purchase_date`, and `aov` (average order value).
593
-
594
- **Permission:** `customers/manage`
595
-
596
- #### Parameters
597
-
598
- | Parameter | Type | Location | Required | Description |
599
- |-----------|------|----------|----------|-------------|
600
- | `customerId` | integer | path | Yes | The customer ID |
601
-
602
- #### Response
603
-
604
- Success (200):
605
-
606
- ```json
607
- {
608
- "message": "Lifetime value recalculated successfully",
609
- "customer": {
610
- "id": 1,
611
- "email": "john@example.com",
612
- "first_name": "John",
613
- "last_name": "Doe",
614
- "purchase_count": 5,
615
- "ltv": 25000,
616
- "aov": 5000,
617
- "first_purchase_date": "2025-01-15 10:30:00",
618
- "last_purchase_date": "2025-06-20 14:00:00"
619
- }
620
- }
621
- ```
622
-
623
- Error (404):
624
-
625
- ```json
626
- {
627
- "message": "Customer not found."
628
- }
629
- ```
630
-
631
- > The LTV calculation sums `total_paid - total_refund` for each order with a successful payment status. Only net-positive amounts are counted.
632
-
633
- #### Example
634
-
635
- ```bash
636
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/recalculate-ltv" \
637
- -u "username:app_password"
638
- ```
639
-
640
- ---
641
-
642
- ## Address Management
643
-
644
- ### Get Customer Addresses
645
-
646
- `GET /fluent-cart/v2/customers/{customerId}/address`
647
-
648
- Retrieve addresses for a customer, optionally filtered by address type. Results are sorted with the primary address first.
649
-
650
- **Permission:** `customers/view`
651
-
652
- #### Parameters
653
-
654
- | Parameter | Type | Location | Required | Description |
655
- |-----------|------|----------|----------|-------------|
656
- | `customerId` | integer | path | Yes | The customer ID |
657
- | `type` | string | query | No | Address type filter: `billing` or `shipping` (default: `billing`) |
658
-
659
- #### Response
660
-
661
- ```json
662
- {
663
- "addresses": [
664
- {
665
- "id": 1,
666
- "customer_id": 1,
667
- "is_primary": 1,
668
- "type": "billing",
669
- "status": "active",
670
- "label": "Home",
671
- "name": "John Doe",
672
- "address_1": "123 Main Street",
673
- "address_2": "Apt 4B",
674
- "city": "New York",
675
- "state": "NY",
676
- "postcode": "10001",
677
- "country": "US",
678
- "phone": "+1-555-0100",
679
- "email": "john@example.com",
680
- "meta": { ... },
681
- "created_at": "2025-01-10 08:00:00",
682
- "updated_at": "2025-06-20 14:00:00",
683
- "formatted_address": {
684
- "country": "United States",
685
- "state": "New York",
686
- "city": "New York",
687
- "postcode": "10001",
688
- "address_1": "123 Main Street",
689
- "address_2": "Apt 4B",
690
- "type": "billing",
691
- "name": "John Doe",
692
- "company_name": "Acme Inc",
693
- "label": "Home",
694
- "phone": "+1-555-0100",
695
- "full_address": "Acme Inc, 123 Main Street, Apt 4B, New York, New York, United States"
696
- },
697
- "company_name": "Acme Inc"
698
- }
699
- ]
700
- }
701
- ```
702
-
703
- #### Example
704
-
705
- ```bash
706
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/address?type=billing" \
707
- -u "username:app_password"
708
- ```
709
-
710
- ---
711
-
712
- ### Create Address
713
-
714
- `POST /fluent-cart/v2/customers/{customerId}/address`
715
-
716
- Create a new address for a customer. If no primary address exists for the given type, this address is automatically set as primary. Optionally syncs with an associated order address.
717
-
718
- **Permission:** `customers/manage`
719
-
720
- #### Parameters
721
-
722
- | Parameter | Type | Location | Required | Description |
723
- |-----------|------|----------|----------|-------------|
724
- | `customerId` | integer | path | Yes | The customer ID |
725
- | `name` | string | body | Yes | Full name for the address. Max 255 characters. |
726
- | `email` | string | body | Yes | Email for the address. Max 255 characters. |
727
- | `address_1` | string | body | Yes | Primary street address |
728
- | `address_2` | string | body | No | Secondary address line (apartment, suite, etc.) |
729
- | `city` | string | body | Yes | City. Max 255 characters. |
730
- | `state` | string | body | Conditional | State/province code. May be required depending on store localization settings. |
731
- | `postcode` | string | body | Conditional | Postal/zip code. May be required depending on store localization settings. |
732
- | `country` | string | body | Yes | Country code (e.g., `US`, `GB`) |
733
- | `phone` | string | body | No | Phone number |
734
- | `type` | string | body | Yes | Address type: `billing` or `shipping` |
735
- | `label` | string | body | No | Custom label for the address (e.g., `Home`, `Office`). Max 15 characters. |
736
- | `status` | string | body | No | Address status (default: `active`) |
737
- | `is_primary` | integer | body | No | Set to `1` to make this the primary address (default: `0`) |
738
- | `company_name` | string | body | No | Company name. Max 255 characters. |
739
- | `order_id` | integer | body | No | Order ID to sync this address with. When provided with a primary address, the corresponding order address is also created/updated. |
740
-
741
- #### Response
742
-
743
- Success (200):
744
-
745
- ```json
746
- {
747
- "message": "Billing address created successfully!",
748
- "data": {
749
- "id": 5,
750
- "customer_id": 1,
751
- "is_primary": 0,
752
- "type": "billing",
753
- "status": "active",
754
- "label": "Office",
755
- "name": "John Doe",
756
- "address_1": "456 Business Ave",
757
- "address_2": "",
758
- "city": "New York",
759
- "state": "NY",
760
- "postcode": "10002",
761
- "country": "US",
762
- "phone": "+1-555-0200",
763
- "email": "john@example.com"
764
- }
765
- }
766
- ```
767
-
768
- #### Example
769
-
770
- ```bash
771
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
772
- -u "username:app_password" \
773
- -H "Content-Type: application/json" \
774
- -d '{
775
- "name": "John Doe",
776
- "email": "john@example.com",
777
- "address_1": "456 Business Ave",
778
- "city": "New York",
779
- "state": "NY",
780
- "postcode": "10002",
781
- "country": "US",
782
- "phone": "+1-555-0200",
783
- "type": "billing",
784
- "label": "Office",
785
- "company_name": "Acme Inc"
786
- }'
787
- ```
788
-
789
- ---
790
-
791
- ### Update Address
792
-
793
- `PUT /fluent-cart/v2/customers/{customerId}/address`
794
-
795
- Update an existing customer address by its address record ID. Optionally syncs changes to an associated order address.
796
-
797
- **Permission:** `customers/manage`
798
-
799
- #### Parameters
800
-
801
- | Parameter | Type | Location | Required | Description |
802
- |-----------|------|----------|----------|-------------|
803
- | `customerId` | integer | path | Yes | The customer ID |
804
- | `id` | integer | body | Yes | The address record ID to update |
805
- | `name` | string | body | Yes | Full name for the address. Max 255 characters. |
806
- | `email` | string | body | Yes | Email for the address. Max 255 characters. |
807
- | `address_1` | string | body | Yes | Primary street address |
808
- | `address_2` | string | body | No | Secondary address line |
809
- | `city` | string | body | Yes | City. Max 255 characters. |
810
- | `state` | string | body | Conditional | State/province code. May be required depending on store localization settings. |
811
- | `postcode` | string | body | Conditional | Postal/zip code. May be required depending on store localization settings. |
812
- | `country` | string | body | Yes | Country code |
813
- | `phone` | string | body | No | Phone number |
814
- | `type` | string | body | Yes | Address type: `billing` or `shipping` |
815
- | `label` | string | body | No | Custom label. Max 15 characters. |
816
- | `status` | string | body | No | Address status |
817
- | `is_primary` | integer | body | No | Set to `1` for primary address |
818
- | `company_name` | string | body | No | Company name. Max 255 characters. |
819
- | `order_id` | integer | body | No | Order ID to sync address changes with |
820
-
821
- #### Response
822
-
823
- Success (200):
824
-
825
- ```json
826
- {
827
- "message": "Billing address updated successfully!",
828
- "data": {
829
- "id": 5,
830
- "customer_id": 1,
831
- "is_primary": 0,
832
- "type": "billing",
833
- "name": "John Doe",
834
- "address_1": "789 Updated Street"
835
- }
836
- }
837
- ```
838
-
839
- Error (404):
840
-
841
- ```json
842
- {
843
- "code": 404,
844
- "message": "Address not found, please reload the page and try again!",
845
- "data": ""
846
- }
847
- ```
848
-
849
- #### Example
850
-
851
- ```bash
852
- curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
853
- -u "username:app_password" \
854
- -H "Content-Type: application/json" \
855
- -d '{
856
- "id": 5,
857
- "name": "John Doe",
858
- "email": "john@example.com",
859
- "address_1": "789 Updated Street",
860
- "city": "New York",
861
- "state": "NY",
862
- "postcode": "10003",
863
- "country": "US",
864
- "type": "billing"
865
- }'
866
- ```
867
-
868
- ---
869
-
870
- ### Delete Address
871
-
872
- `DELETE /fluent-cart/v2/customers/{customerId}/address`
873
-
874
- Delete a customer address. Primary addresses and the last remaining address cannot be deleted.
875
-
876
- **Permission:** `customers/delete`
877
-
878
- #### Parameters
879
-
880
- | Parameter | Type | Location | Required | Description |
881
- |-----------|------|----------|----------|-------------|
882
- | `customerId` | integer | path | Yes | The customer ID |
883
- | `address[id]` | integer | body/query | Yes | The address record ID to delete |
884
-
885
- #### Response
886
-
887
- Success (200):
888
-
889
- ```json
890
- {
891
- "message": "Address successfully deleted.",
892
- "data": ""
893
- }
894
- ```
895
-
896
- Error (primary address):
897
-
898
- ```json
899
- {
900
- "code": 403,
901
- "message": "Primary address cannot be deleted!",
902
- "data": ""
903
- }
904
- ```
905
-
906
- Error (last address):
907
-
908
- ```json
909
- {
910
- "code": 403,
911
- "message": "At least one address must remain. Address deletion failed!",
912
- "data": ""
913
- }
914
- ```
915
-
916
- #### Example
917
-
918
- ```bash
919
- curl -X DELETE "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
920
- -u "username:app_password" \
921
- -H "Content-Type: application/json" \
922
- -d '{
923
- "address": {
924
- "id": 5
925
- }
926
- }'
927
- ```
928
-
929
- ---
930
-
931
- ### Set Primary Address
932
-
933
- `POST /fluent-cart/v2/customers/{customerId}/address/make-primary`
934
-
935
- Set a specific address as the primary address for its type. The previous primary address of the same type is automatically demoted.
936
-
937
- **Permission:** `customers/manage`
938
-
939
- #### Parameters
940
-
941
- | Parameter | Type | Location | Required | Description |
942
- |-----------|------|----------|----------|-------------|
943
- | `customerId` | integer | path | Yes | The customer ID |
944
- | `addressId` | integer | body | Yes | The address record ID to make primary |
945
- | `type` | string | body | Yes | Address type: `billing` or `shipping` |
946
-
947
- #### Response
948
-
949
- Success (200):
950
-
951
- ```json
952
- {
953
- "message": "Address successfully set as the primary",
954
- "data": ""
955
- }
956
- ```
957
-
958
- Error (400):
959
-
960
- ```json
961
- {
962
- "code": 400,
963
- "message": "Address set as primary failed.",
964
- "data": ""
965
- }
966
- ```
967
-
968
- #### Example
969
-
970
- ```bash
971
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/address/make-primary" \
972
- -u "username:app_password" \
973
- -H "Content-Type: application/json" \
974
- -d '{
975
- "addressId": 5,
976
- "type": "billing"
977
- }'
978
- ```
979
-
980
- ---
981
-
982
- ## User Association
983
-
984
- ### Get Attachable Users
985
-
986
- `GET /fluent-cart/v2/customers/attachable-user`
987
-
988
- Retrieve a list of WordPress users that are not yet associated with any FluentCart customer. Useful for linking existing WP users to customer records.
989
-
990
- **Permission:** `customers/manage`
991
-
992
- #### Response
993
-
994
- ```json
995
- {
996
- "users": [
997
- {
998
- "ID": 10,
999
- "display_name": "Alice Johnson",
1000
- "user_email": "alice@example.com"
1001
- },
1002
- {
1003
- "ID": 15,
1004
- "display_name": "Bob Wilson",
1005
- "user_email": "bob@example.com"
1006
- }
1007
- ]
1008
- }
1009
- ```
1010
-
1011
- #### Example
1012
-
1013
- ```bash
1014
- curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/attachable-user" \
1015
- -u "username:app_password"
1016
- ```
1017
-
1018
- ---
1019
-
1020
- ### Attach WordPress User
1021
-
1022
- `POST /fluent-cart/v2/customers/{customerId}/attachable-user`
1023
-
1024
- Link a WordPress user to an existing customer record. The customer must not already have a linked user, and the target user must not already be linked to another customer.
1025
-
1026
- **Permission:** `customers/manage`
1027
-
1028
- #### Parameters
1029
-
1030
- | Parameter | Type | Location | Required | Description |
1031
- |-----------|------|----------|----------|-------------|
1032
- | `customerId` | integer | path | Yes | The customer ID |
1033
- | `user_id` | integer | body | Yes | The WordPress user ID to attach. Max 50 characters. Must reference an existing user who is not already linked to a customer. |
1034
-
1035
- #### Response
1036
-
1037
- Success (200):
1038
-
1039
- ```json
1040
- {
1041
- "message": "User attached successfully"
1042
- }
1043
- ```
1044
-
1045
- Error (customer already has user):
1046
-
1047
- ```json
1048
- {
1049
- "message": "Can not attach user"
1050
- }
1051
- ```
1052
-
1053
- Error (user already linked):
1054
-
1055
- ```json
1056
- {
1057
- "code": "rest_request_validation",
1058
- "message": "User already linked to a customer."
1059
- }
1060
- ```
1061
-
1062
- Error (user not found):
1063
-
1064
- ```json
1065
- {
1066
- "code": "rest_request_validation",
1067
- "message": "User not found."
1068
- }
1069
- ```
1070
-
1071
- #### Example
1072
-
1073
- ```bash
1074
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/attachable-user" \
1075
- -u "username:app_password" \
1076
- -H "Content-Type: application/json" \
1077
- -d '{
1078
- "user_id": 10
1079
- }'
1080
- ```
1081
-
1082
- ---
1083
-
1084
- ### Detach WordPress User
1085
-
1086
- `POST /fluent-cart/v2/customers/{customerId}/detach-user`
1087
-
1088
- Remove the WordPress user association from a customer record. The customer record itself is preserved; only the `user_id` link is cleared.
1089
-
1090
- **Permission:** `customers/manage`
1091
-
1092
- #### Parameters
1093
-
1094
- | Parameter | Type | Location | Required | Description |
1095
- |-----------|------|----------|----------|-------------|
1096
- | `customerId` | integer | path | Yes | The customer ID |
1097
-
1098
- #### Response
1099
-
1100
- Success (200):
1101
-
1102
- ```json
1103
- {
1104
- "message": "User detached successfully"
1105
- }
1106
- ```
1107
-
1108
- Error (customer not found):
1109
-
1110
- ```json
1111
- {
1112
- "message": "Customer not found."
1113
- }
1114
- ```
1115
-
1116
- #### Example
1117
-
1118
- ```bash
1119
- curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/detach-user" \
1120
- -u "username:app_password"
1121
- ```
1
+ # Customers API
2
+
3
+ Manage customer records including creating customers, managing addresses, associating WordPress users, and viewing customer order history.
4
+
5
+ **Base URL:** `https://your-site.com/wp-json/fluent-cart/v2/customers`
6
+
7
+ **Policy:** `CustomerPolicy`
8
+
9
+ > All monetary values are in cents (e.g., `$10.00` = `1000`).
10
+
11
+ ---
12
+
13
+ ## Endpoints Overview
14
+
15
+ | Method | Endpoint | Description |
16
+ |--------|----------|-------------|
17
+ | **Customer CRUD** | | |
18
+ | GET | `/customers` | List Customers |
19
+ | POST | `/customers` | Create Customer |
20
+ | GET | `/customers/{customerId}` | Get Customer |
21
+ | PUT | `/customers/{customerId}` | Update Customer |
22
+ | PUT | `/customers/{customerId}/additional-info` | Update Additional Info (Labels) |
23
+ | POST | `/customers/do-bulk-action` | Bulk Actions |
24
+ | **Stats & Orders** | | |
25
+ | GET | `/customers/get-stats/{customer}` | Get Customer Stats |
26
+ | GET | `/customers/{customerId}/orders` | Get Customer Orders |
27
+ | GET | `/customers/{customerId}/order` | Find Customer Order |
28
+ | POST | `/customers/{customerId}/recalculate-ltv` | Recalculate Lifetime Value |
29
+ | **Address Management** | | |
30
+ | GET | `/customers/{customerId}/address` | Get Customer Addresses |
31
+ | POST | `/customers/{customerId}/address` | Create Address |
32
+ | PUT | `/customers/{customerId}/address` | Update Address |
33
+ | DELETE | `/customers/{customerId}/address` | Delete Address |
34
+ | POST | `/customers/{customerId}/address/make-primary` | Set Primary Address |
35
+ | **User Association** | | |
36
+ | GET | `/customers/attachable-user` | Get Attachable Users |
37
+ | POST | `/customers/{customerId}/attachable-user` | Attach WordPress User |
38
+ | POST | `/customers/{customerId}/detach-user` | Detach WordPress User |
39
+
40
+ ---
41
+
42
+ ## Customer CRUD
43
+
44
+ ### List Customers
45
+
46
+ `GET /fluent-cart/v2/customers`
47
+
48
+ Retrieve a paginated list of customers with support for searching, sorting, and advanced filtering.
49
+
50
+ **Permission:** `customers/view`
51
+
52
+ #### Parameters
53
+
54
+ | Parameter | Type | Location | Required | Description |
55
+ |-----------|------|----------|----------|-------------|
56
+ | `search` | string | query | No | Search by customer name, email, or ID. Supports operator syntax (e.g., `id=5`, `ltv>1000`). |
57
+ | `per_page` | integer | query | No | Number of items per page (1-199, default: 10) |
58
+ | `page` | integer | query | No | Page number for pagination |
59
+ | `sort_by` | string | query | No | Column to sort by. Must be a fillable field on the Customer model (default: `id`) |
60
+ | `sort_type` | string | query | No | Sort direction: `asc` or `desc` (default: `desc`) |
61
+ | `filter_type` | string | query | No | Filter mode: `simple` or `advanced` (default: `simple`) |
62
+ | `advanced_filters` | string (JSON) | query | No | JSON-encoded array of advanced filter groups (Pro only). Supports filtering by order items, purchase count, purchase dates, customer name, email, LTV, and labels. |
63
+ | `with` | array | query | No | Relationships to eager-load (e.g., `orders`, `labels`, `billing_address`, `shipping_address`) |
64
+ | `select` | string/array | query | No | Comma-separated column names or array of columns to select |
65
+ | `include_ids` | string/array | query | No | Comma-separated IDs or array of IDs that must be included in results |
66
+ | `active_view` | string | query | No | Active tab/view filter |
67
+ | `user_tz` | string | query | No | User timezone for date filter conversion |
68
+
69
+ #### Response
70
+
71
+ ```json
72
+ {
73
+ "customers": {
74
+ "total": 150,
75
+ "per_page": 10,
76
+ "current_page": 1,
77
+ "last_page": 15,
78
+ "data": [
79
+ {
80
+ "id": 1,
81
+ "user_id": 5,
82
+ "contact_id": null,
83
+ "email": "john@example.com",
84
+ "first_name": "John",
85
+ "last_name": "Doe",
86
+ "status": "active",
87
+ "purchase_value": { ... },
88
+ "purchase_count": 3,
89
+ "ltv": 15000,
90
+ "first_purchase_date": "2025-01-15 10:30:00",
91
+ "last_purchase_date": "2025-06-20 14:00:00",
92
+ "aov": 5000,
93
+ "notes": "",
94
+ "uuid": "a1b2c3d4...",
95
+ "country": "US",
96
+ "city": "New York",
97
+ "state": "NY",
98
+ "postcode": "10001",
99
+ "created_at": "2025-01-10 08:00:00",
100
+ "updated_at": "2025-06-20 14:00:00",
101
+ "full_name": "John Doe",
102
+ "photo": "https://gravatar.com/avatar/...",
103
+ "country_name": "United States",
104
+ "formatted_address": { ... },
105
+ "user_link": "https://example.com/wp-admin/user-edit.php?user_id=5"
106
+ }
107
+ ]
108
+ }
109
+ }
110
+ ```
111
+
112
+ #### Example
113
+
114
+ ```bash
115
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers?per_page=20&search=john&sort_by=created_at&sort_type=desc" \
116
+ -u "username:app_password"
117
+ ```
118
+
119
+ ---
120
+
121
+ ### Create Customer
122
+
123
+ `POST /fluent-cart/v2/customers`
124
+
125
+ Create a new customer record. Automatically links to an existing WordPress user if a matching email is found.
126
+
127
+ **Permission:** `customers/manage`
128
+
129
+ #### Parameters
130
+
131
+ | Parameter | Type | Location | Required | Description |
132
+ |-----------|------|----------|----------|-------------|
133
+ | `email` | string | body | Yes | Customer email address. Must be unique and valid. Max 255 characters. |
134
+ | `first_name` | string | body | Conditional | Customer first name. Required when store is not configured for full name mode. Max 255 characters. |
135
+ | `last_name` | string | body | No | Customer last name. Max 255 characters. |
136
+ | `full_name` | string | body | Conditional | Customer full name. Required when store is configured for full name mode. Max 255 characters. Automatically split into `first_name` and `last_name`. |
137
+ | `city` | string | body | No | Customer city |
138
+ | `state` | string | body | No | Customer state/province code |
139
+ | `postcode` | string | body | No | Customer postal/zip code |
140
+ | `country` | string | body | No | Customer country code (e.g., `US`, `GB`) |
141
+ | `notes` | string | body | No | Internal notes about the customer |
142
+ | `status` | string | body | No | Customer status |
143
+ | `user_id` | integer | body | No | WordPress user ID to associate |
144
+ | `wp_user` | string | body | No | Set to `yes` to create a new WordPress user account for this customer |
145
+ | `aov` | string | body | No | Average order value |
146
+ | `user_url` | string | body | No | Customer website URL |
147
+
148
+ #### Response
149
+
150
+ Success (200):
151
+
152
+ ```json
153
+ {
154
+ "message": "Customer created successfully!",
155
+ "data": {
156
+ "id": 42,
157
+ "user_id": null,
158
+ "email": "jane@example.com",
159
+ "first_name": "Jane",
160
+ "last_name": "Smith",
161
+ "status": "active",
162
+ "purchase_value": [],
163
+ "uuid": "e5f6g7h8...",
164
+ "country": "US",
165
+ "city": "Boston",
166
+ "state": "MA",
167
+ "postcode": "02101",
168
+ "created_at": "2025-06-20 14:00:00",
169
+ "updated_at": "2025-06-20 14:00:00"
170
+ }
171
+ }
172
+ ```
173
+
174
+ Error (email already exists):
175
+
176
+ ```json
177
+ {
178
+ "code": 400,
179
+ "message": "Customer already exists.",
180
+ "data": ""
181
+ }
182
+ ```
183
+
184
+ #### Example
185
+
186
+ ```bash
187
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers" \
188
+ -u "username:app_password" \
189
+ -H "Content-Type: application/json" \
190
+ -d '{
191
+ "first_name": "Jane",
192
+ "last_name": "Smith",
193
+ "email": "jane@example.com",
194
+ "country": "US",
195
+ "city": "Boston",
196
+ "state": "MA",
197
+ "postcode": "02101",
198
+ "wp_user": "yes"
199
+ }'
200
+ ```
201
+
202
+ ---
203
+
204
+ ### Get Customer
205
+
206
+ `GET /fluent-cart/v2/customers/{customerId}`
207
+
208
+ Retrieve a single customer by ID with optional eager-loaded relationships.
209
+
210
+ **Permission:** `customers/view`
211
+
212
+ #### Parameters
213
+
214
+ | Parameter | Type | Location | Required | Description |
215
+ |-----------|------|----------|----------|-------------|
216
+ | `customerId` | integer | path | Yes | The customer ID |
217
+ | `with` | array | query | No | Relationships to eager-load (e.g., `orders`, `labels`, `billing_address`, `shipping_address`, `subscriptions`, `wpUser`) |
218
+ | `params[customer_only]` | string | query | No | Set to `yes` to return the customer without labels processing |
219
+
220
+ #### Response
221
+
222
+ ```json
223
+ {
224
+ "customer": {
225
+ "id": 1,
226
+ "user_id": 5,
227
+ "contact_id": null,
228
+ "email": "john@example.com",
229
+ "first_name": "John",
230
+ "last_name": "Doe",
231
+ "status": "active",
232
+ "purchase_value": { ... },
233
+ "purchase_count": 3,
234
+ "ltv": 15000,
235
+ "first_purchase_date": "2025-01-15 10:30:00",
236
+ "last_purchase_date": "2025-06-20 14:00:00",
237
+ "aov": 5000,
238
+ "notes": "",
239
+ "uuid": "a1b2c3d4...",
240
+ "country": "US",
241
+ "city": "New York",
242
+ "state": "NY",
243
+ "postcode": "10001",
244
+ "created_at": "2025-01-10 08:00:00",
245
+ "updated_at": "2025-06-20 14:00:00",
246
+ "full_name": "John Doe",
247
+ "photo": "https://gravatar.com/avatar/...",
248
+ "country_name": "United States",
249
+ "formatted_address": {
250
+ "country": "United States",
251
+ "state": "New York",
252
+ "city": "New York",
253
+ "postcode": "10001",
254
+ "first_name": "John",
255
+ "last_name": "Doe",
256
+ "full_name": "John Doe"
257
+ },
258
+ "user_link": "https://example.com/wp-admin/user-edit.php?user_id=5",
259
+ "selected_labels": [1, 3, 7],
260
+ "labels": [ ... ]
261
+ }
262
+ }
263
+ ```
264
+
265
+ Error (404):
266
+
267
+ ```json
268
+ {
269
+ "message": "Customer not found",
270
+ "back_text": "Back to Customer List",
271
+ "back_url": "/customers"
272
+ }
273
+ ```
274
+
275
+ #### Example
276
+
277
+ ```bash
278
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1?with[]=labels&with[]=billing_address" \
279
+ -u "username:app_password"
280
+ ```
281
+
282
+ ---
283
+
284
+ ### Update Customer
285
+
286
+ `PUT /fluent-cart/v2/customers/{customerId}`
287
+
288
+ Update an existing customer. If the customer is linked to a WordPress user, the corresponding WP user profile is also updated.
289
+
290
+ **Permission:** `customers/manage`
291
+
292
+ #### Parameters
293
+
294
+ | Parameter | Type | Location | Required | Description |
295
+ |-----------|------|----------|----------|-------------|
296
+ | `customerId` | integer | path | Yes | The customer ID |
297
+ | `email` | string | body | Yes | Customer email address. Must be unique (excluding current customer). Max 255 characters. |
298
+ | `first_name` | string | body | Conditional | Customer first name. Required when store is not configured for full name mode. Max 255 characters. |
299
+ | `last_name` | string | body | No | Customer last name. Max 255 characters. |
300
+ | `full_name` | string | body | Conditional | Customer full name. Required when store is configured for full name mode. Max 255 characters. |
301
+ | `city` | string | body | No | Customer city |
302
+ | `state` | string | body | No | Customer state/province code |
303
+ | `postcode` | string | body | No | Customer postal/zip code |
304
+ | `country` | string | body | No | Customer country code |
305
+ | `notes` | string | body | No | Internal notes about the customer |
306
+ | `status` | string | body | No | Customer status |
307
+ | `user_id` | integer | body | No | WordPress user ID |
308
+ | `aov` | string | body | No | Average order value |
309
+ | `user_url` | string | body | No | Customer website URL |
310
+ | `username` | string | body | No | Username |
311
+ | `user_nicename` | string | body | No | User nicename |
312
+ | `display_name` | string | body | No | Display name |
313
+
314
+ #### Response
315
+
316
+ Success (200):
317
+
318
+ ```json
319
+ {
320
+ "message": "Customer updated successfully!",
321
+ "data": {
322
+ "id": 1,
323
+ "user_id": 5,
324
+ "email": "john@example.com",
325
+ "first_name": "John",
326
+ "last_name": "Doe",
327
+ "status": "active"
328
+ }
329
+ }
330
+ ```
331
+
332
+ #### Example
333
+
334
+ ```bash
335
+ curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1" \
336
+ -u "username:app_password" \
337
+ -H "Content-Type: application/json" \
338
+ -d '{
339
+ "first_name": "John",
340
+ "last_name": "Doe",
341
+ "email": "john@example.com",
342
+ "city": "San Francisco",
343
+ "state": "CA",
344
+ "country": "US"
345
+ }'
346
+ ```
347
+
348
+ ---
349
+
350
+ ### Update Additional Info (Labels)
351
+
352
+ `PUT /fluent-cart/v2/customers/{customerId}/additional-info`
353
+
354
+ Update a customer's labels/tags. Manages the label relationships for a customer by syncing provided label IDs with existing ones.
355
+
356
+ **Permission:** `customers/manage`
357
+
358
+ #### Parameters
359
+
360
+ | Parameter | Type | Location | Required | Description |
361
+ |-----------|------|----------|----------|-------------|
362
+ | `customerId` | integer | path | Yes | The customer ID |
363
+ | `labels` | array | body | Yes | Array of label IDs to assign to the customer. Existing labels not in this array will be removed. |
364
+
365
+ #### Response
366
+
367
+ Success (200):
368
+
369
+ ```json
370
+ {
371
+ "message": "Customer updated successfully!",
372
+ "data": { ... }
373
+ }
374
+ ```
375
+
376
+ #### Example
377
+
378
+ ```bash
379
+ curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1/additional-info" \
380
+ -u "username:app_password" \
381
+ -H "Content-Type: application/json" \
382
+ -d '{
383
+ "labels": [1, 3, 7]
384
+ }'
385
+ ```
386
+
387
+ ---
388
+
389
+ ### Bulk Actions
390
+
391
+ `POST /fluent-cart/v2/customers/do-bulk-action`
392
+
393
+ Perform bulk operations on multiple customers such as deletion or status change.
394
+
395
+ **Permission:** `customers/manage`
396
+
397
+ #### Parameters
398
+
399
+ | Parameter | Type | Location | Required | Description |
400
+ |-----------|------|----------|----------|-------------|
401
+ | `action` | string | body | Yes | The action to perform. Supported values: `delete_customers`, `change_customer_status` |
402
+ | `customer_ids` | array | body | Yes | Array of customer IDs to act upon |
403
+ | `new_status` | string | body | Conditional | Required when action is `change_customer_status`. The new status to apply to the selected customers. Must be a valid editable customer status. |
404
+
405
+ #### Response
406
+
407
+ Success (`delete_customers`):
408
+
409
+ ```json
410
+ {
411
+ "message": "Selected Customers has been deleted permanently",
412
+ "data": ""
413
+ }
414
+ ```
415
+
416
+ Success (`change_customer_status`):
417
+
418
+ ```json
419
+ {
420
+ "message": "Customer Status has been changed",
421
+ "data": ""
422
+ }
423
+ ```
424
+
425
+ Error (missing selection):
426
+
427
+ ```json
428
+ {
429
+ "code": 403,
430
+ "message": "Customers selection is required",
431
+ "data": ""
432
+ }
433
+ ```
434
+
435
+ #### Example
436
+
437
+ ```bash
438
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/do-bulk-action" \
439
+ -u "username:app_password" \
440
+ -H "Content-Type: application/json" \
441
+ -d '{
442
+ "action": "change_customer_status",
443
+ "customer_ids": [1, 2, 3],
444
+ "new_status": "archived"
445
+ }'
446
+ ```
447
+
448
+ ---
449
+
450
+ ## Customer Stats & Orders
451
+
452
+ ### Get Customer Stats
453
+
454
+ `GET /fluent-cart/v2/customers/get-stats/{customer}`
455
+
456
+ Retrieve widget/stats data for a specific customer. Results are extensible via the `fluent_cart/widgets/single_customer` filter.
457
+
458
+ **Permission:** `customers/view`
459
+
460
+ #### Parameters
461
+
462
+ | Parameter | Type | Location | Required | Description |
463
+ |-----------|------|----------|----------|-------------|
464
+ | `customer` | integer | path | Yes | The customer ID |
465
+
466
+ #### Response
467
+
468
+ ```json
469
+ {
470
+ "widgets": []
471
+ }
472
+ ```
473
+
474
+ The `widgets` array is populated by modules and extensions that hook into the `fluent_cart/widgets/single_customer` filter.
475
+
476
+ #### Example
477
+
478
+ ```bash
479
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/get-stats/1" \
480
+ -u "username:app_password"
481
+ ```
482
+
483
+ ---
484
+
485
+ ### Get Customer Orders
486
+
487
+ `GET /fluent-cart/v2/customers/{customerId}/orders`
488
+
489
+ Retrieve a paginated list of orders belonging to a specific customer. Supports the same filtering and sorting parameters as the main Orders list.
490
+
491
+ **Permission:** `customers/view`
492
+
493
+ #### Parameters
494
+
495
+ | Parameter | Type | Location | Required | Description |
496
+ |-----------|------|----------|----------|-------------|
497
+ | `customerId` | integer | path | Yes | The customer ID |
498
+ | `search` | string | query | No | Search orders by invoice number, customer name/email, or order item title |
499
+ | `per_page` | integer | query | No | Number of items per page (1-199, default: 10) |
500
+ | `page` | integer | query | No | Page number for pagination |
501
+ | `sort_by` | string | query | No | Column to sort by (default: `id`) |
502
+ | `sort_type` | string | query | No | Sort direction: `asc` or `desc` (default: `desc`) |
503
+ | `filter_type` | string | query | No | Filter mode: `simple` or `advanced` (default: `simple`) |
504
+ | `advanced_filters` | string (JSON) | query | No | JSON-encoded array of advanced filter groups |
505
+ | `active_view` | string | query | No | Active tab filter (e.g., `on-hold`, `paid`, `completed`, `processing`) |
506
+
507
+ #### Response
508
+
509
+ ```json
510
+ {
511
+ "orders": {
512
+ "total": 5,
513
+ "per_page": 10,
514
+ "current_page": 1,
515
+ "last_page": 1,
516
+ "data": [
517
+ {
518
+ "id": 101,
519
+ "invoice_no": "FCT-0101",
520
+ "customer_id": 1,
521
+ "status": "completed",
522
+ "payment_status": "paid",
523
+ "total_amount": 5000
524
+ }
525
+ ]
526
+ }
527
+ }
528
+ ```
529
+
530
+ #### Example
531
+
532
+ ```bash
533
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/orders?per_page=10&sort_by=created_at&sort_type=desc" \
534
+ -u "username:app_password"
535
+ ```
536
+
537
+ ---
538
+
539
+ ### Find Customer Order
540
+
541
+ `GET /fluent-cart/v2/customers/{customerId}/order`
542
+
543
+ Retrieve all orders for a customer with their filtered order items (line items) eager-loaded.
544
+
545
+ **Permission:** `customers/view`
546
+
547
+ #### Parameters
548
+
549
+ | Parameter | Type | Location | Required | Description |
550
+ |-----------|------|----------|----------|-------------|
551
+ | `customerId` | integer | path | Yes | The customer ID |
552
+
553
+ #### Response
554
+
555
+ ```json
556
+ {
557
+ "data": {
558
+ "data": [
559
+ {
560
+ "id": 101,
561
+ "customer_id": 1,
562
+ "invoice_no": "FCT-0101",
563
+ "total_amount": 5000,
564
+ "filtered_order_items": [
565
+ {
566
+ "id": 1,
567
+ "order_id": 101,
568
+ "title": "Product Name",
569
+ "quantity": 2,
570
+ "unit_price": 2500
571
+ }
572
+ ]
573
+ }
574
+ ]
575
+ }
576
+ }
577
+ ```
578
+
579
+ #### Example
580
+
581
+ ```bash
582
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/order" \
583
+ -u "username:app_password"
584
+ ```
585
+
586
+ ---
587
+
588
+ ### Recalculate Lifetime Value
589
+
590
+ `POST /fluent-cart/v2/customers/{customerId}/recalculate-ltv`
591
+
592
+ Recalculate a customer's lifetime value (LTV) by summing net payments from all successful orders. Also updates `purchase_count`, `first_purchase_date`, `last_purchase_date`, and `aov` (average order value).
593
+
594
+ **Permission:** `customers/manage`
595
+
596
+ #### Parameters
597
+
598
+ | Parameter | Type | Location | Required | Description |
599
+ |-----------|------|----------|----------|-------------|
600
+ | `customerId` | integer | path | Yes | The customer ID |
601
+
602
+ #### Response
603
+
604
+ Success (200):
605
+
606
+ ```json
607
+ {
608
+ "message": "Lifetime value recalculated successfully",
609
+ "customer": {
610
+ "id": 1,
611
+ "email": "john@example.com",
612
+ "first_name": "John",
613
+ "last_name": "Doe",
614
+ "purchase_count": 5,
615
+ "ltv": 25000,
616
+ "aov": 5000,
617
+ "first_purchase_date": "2025-01-15 10:30:00",
618
+ "last_purchase_date": "2025-06-20 14:00:00"
619
+ }
620
+ }
621
+ ```
622
+
623
+ Error (404):
624
+
625
+ ```json
626
+ {
627
+ "message": "Customer not found."
628
+ }
629
+ ```
630
+
631
+ > The LTV calculation sums `total_paid - total_refund` for each order with a successful payment status. Only net-positive amounts are counted.
632
+
633
+ #### Example
634
+
635
+ ```bash
636
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/recalculate-ltv" \
637
+ -u "username:app_password"
638
+ ```
639
+
640
+ ---
641
+
642
+ ## Address Management
643
+
644
+ ### Get Customer Addresses
645
+
646
+ `GET /fluent-cart/v2/customers/{customerId}/address`
647
+
648
+ Retrieve addresses for a customer, optionally filtered by address type. Results are sorted with the primary address first.
649
+
650
+ **Permission:** `customers/view`
651
+
652
+ #### Parameters
653
+
654
+ | Parameter | Type | Location | Required | Description |
655
+ |-----------|------|----------|----------|-------------|
656
+ | `customerId` | integer | path | Yes | The customer ID |
657
+ | `type` | string | query | No | Address type filter: `billing` or `shipping` (default: `billing`) |
658
+
659
+ #### Response
660
+
661
+ ```json
662
+ {
663
+ "addresses": [
664
+ {
665
+ "id": 1,
666
+ "customer_id": 1,
667
+ "is_primary": 1,
668
+ "type": "billing",
669
+ "status": "active",
670
+ "label": "Home",
671
+ "name": "John Doe",
672
+ "address_1": "123 Main Street",
673
+ "address_2": "Apt 4B",
674
+ "city": "New York",
675
+ "state": "NY",
676
+ "postcode": "10001",
677
+ "country": "US",
678
+ "phone": "+1-555-0100",
679
+ "email": "john@example.com",
680
+ "meta": { ... },
681
+ "created_at": "2025-01-10 08:00:00",
682
+ "updated_at": "2025-06-20 14:00:00",
683
+ "formatted_address": {
684
+ "country": "United States",
685
+ "state": "New York",
686
+ "city": "New York",
687
+ "postcode": "10001",
688
+ "address_1": "123 Main Street",
689
+ "address_2": "Apt 4B",
690
+ "type": "billing",
691
+ "name": "John Doe",
692
+ "company_name": "Acme Inc",
693
+ "label": "Home",
694
+ "phone": "+1-555-0100",
695
+ "full_address": "Acme Inc, 123 Main Street, Apt 4B, New York, New York, United States"
696
+ },
697
+ "company_name": "Acme Inc"
698
+ }
699
+ ]
700
+ }
701
+ ```
702
+
703
+ #### Example
704
+
705
+ ```bash
706
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/1/address?type=billing" \
707
+ -u "username:app_password"
708
+ ```
709
+
710
+ ---
711
+
712
+ ### Create Address
713
+
714
+ `POST /fluent-cart/v2/customers/{customerId}/address`
715
+
716
+ Create a new address for a customer. If no primary address exists for the given type, this address is automatically set as primary. Optionally syncs with an associated order address.
717
+
718
+ **Permission:** `customers/manage`
719
+
720
+ #### Parameters
721
+
722
+ | Parameter | Type | Location | Required | Description |
723
+ |-----------|------|----------|----------|-------------|
724
+ | `customerId` | integer | path | Yes | The customer ID |
725
+ | `name` | string | body | Yes | Full name for the address. Max 255 characters. |
726
+ | `email` | string | body | Yes | Email for the address. Max 255 characters. |
727
+ | `address_1` | string | body | Yes | Primary street address |
728
+ | `address_2` | string | body | No | Secondary address line (apartment, suite, etc.) |
729
+ | `city` | string | body | Yes | City. Max 255 characters. |
730
+ | `state` | string | body | Conditional | State/province code. May be required depending on store localization settings. |
731
+ | `postcode` | string | body | Conditional | Postal/zip code. May be required depending on store localization settings. |
732
+ | `country` | string | body | Yes | Country code (e.g., `US`, `GB`) |
733
+ | `phone` | string | body | No | Phone number |
734
+ | `type` | string | body | Yes | Address type: `billing` or `shipping` |
735
+ | `label` | string | body | No | Custom label for the address (e.g., `Home`, `Office`). Max 15 characters. |
736
+ | `status` | string | body | No | Address status (default: `active`) |
737
+ | `is_primary` | integer | body | No | Set to `1` to make this the primary address (default: `0`) |
738
+ | `company_name` | string | body | No | Company name. Max 255 characters. |
739
+ | `order_id` | integer | body | No | Order ID to sync this address with. When provided with a primary address, the corresponding order address is also created/updated. |
740
+
741
+ #### Response
742
+
743
+ Success (200):
744
+
745
+ ```json
746
+ {
747
+ "message": "Billing address created successfully!",
748
+ "data": {
749
+ "id": 5,
750
+ "customer_id": 1,
751
+ "is_primary": 0,
752
+ "type": "billing",
753
+ "status": "active",
754
+ "label": "Office",
755
+ "name": "John Doe",
756
+ "address_1": "456 Business Ave",
757
+ "address_2": "",
758
+ "city": "New York",
759
+ "state": "NY",
760
+ "postcode": "10002",
761
+ "country": "US",
762
+ "phone": "+1-555-0200",
763
+ "email": "john@example.com"
764
+ }
765
+ }
766
+ ```
767
+
768
+ #### Example
769
+
770
+ ```bash
771
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
772
+ -u "username:app_password" \
773
+ -H "Content-Type: application/json" \
774
+ -d '{
775
+ "name": "John Doe",
776
+ "email": "john@example.com",
777
+ "address_1": "456 Business Ave",
778
+ "city": "New York",
779
+ "state": "NY",
780
+ "postcode": "10002",
781
+ "country": "US",
782
+ "phone": "+1-555-0200",
783
+ "type": "billing",
784
+ "label": "Office",
785
+ "company_name": "Acme Inc"
786
+ }'
787
+ ```
788
+
789
+ ---
790
+
791
+ ### Update Address
792
+
793
+ `PUT /fluent-cart/v2/customers/{customerId}/address`
794
+
795
+ Update an existing customer address by its address record ID. Optionally syncs changes to an associated order address.
796
+
797
+ **Permission:** `customers/manage`
798
+
799
+ #### Parameters
800
+
801
+ | Parameter | Type | Location | Required | Description |
802
+ |-----------|------|----------|----------|-------------|
803
+ | `customerId` | integer | path | Yes | The customer ID |
804
+ | `id` | integer | body | Yes | The address record ID to update |
805
+ | `name` | string | body | Yes | Full name for the address. Max 255 characters. |
806
+ | `email` | string | body | Yes | Email for the address. Max 255 characters. |
807
+ | `address_1` | string | body | Yes | Primary street address |
808
+ | `address_2` | string | body | No | Secondary address line |
809
+ | `city` | string | body | Yes | City. Max 255 characters. |
810
+ | `state` | string | body | Conditional | State/province code. May be required depending on store localization settings. |
811
+ | `postcode` | string | body | Conditional | Postal/zip code. May be required depending on store localization settings. |
812
+ | `country` | string | body | Yes | Country code |
813
+ | `phone` | string | body | No | Phone number |
814
+ | `type` | string | body | Yes | Address type: `billing` or `shipping` |
815
+ | `label` | string | body | No | Custom label. Max 15 characters. |
816
+ | `status` | string | body | No | Address status |
817
+ | `is_primary` | integer | body | No | Set to `1` for primary address |
818
+ | `company_name` | string | body | No | Company name. Max 255 characters. |
819
+ | `order_id` | integer | body | No | Order ID to sync address changes with |
820
+
821
+ #### Response
822
+
823
+ Success (200):
824
+
825
+ ```json
826
+ {
827
+ "message": "Billing address updated successfully!",
828
+ "data": {
829
+ "id": 5,
830
+ "customer_id": 1,
831
+ "is_primary": 0,
832
+ "type": "billing",
833
+ "name": "John Doe",
834
+ "address_1": "789 Updated Street"
835
+ }
836
+ }
837
+ ```
838
+
839
+ Error (404):
840
+
841
+ ```json
842
+ {
843
+ "code": 404,
844
+ "message": "Address not found, please reload the page and try again!",
845
+ "data": ""
846
+ }
847
+ ```
848
+
849
+ #### Example
850
+
851
+ ```bash
852
+ curl -X PUT "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
853
+ -u "username:app_password" \
854
+ -H "Content-Type: application/json" \
855
+ -d '{
856
+ "id": 5,
857
+ "name": "John Doe",
858
+ "email": "john@example.com",
859
+ "address_1": "789 Updated Street",
860
+ "city": "New York",
861
+ "state": "NY",
862
+ "postcode": "10003",
863
+ "country": "US",
864
+ "type": "billing"
865
+ }'
866
+ ```
867
+
868
+ ---
869
+
870
+ ### Delete Address
871
+
872
+ `DELETE /fluent-cart/v2/customers/{customerId}/address`
873
+
874
+ Delete a customer address. Primary addresses and the last remaining address cannot be deleted.
875
+
876
+ **Permission:** `customers/delete`
877
+
878
+ #### Parameters
879
+
880
+ | Parameter | Type | Location | Required | Description |
881
+ |-----------|------|----------|----------|-------------|
882
+ | `customerId` | integer | path | Yes | The customer ID |
883
+ | `address[id]` | integer | body/query | Yes | The address record ID to delete |
884
+
885
+ #### Response
886
+
887
+ Success (200):
888
+
889
+ ```json
890
+ {
891
+ "message": "Address successfully deleted.",
892
+ "data": ""
893
+ }
894
+ ```
895
+
896
+ Error (primary address):
897
+
898
+ ```json
899
+ {
900
+ "code": 403,
901
+ "message": "Primary address cannot be deleted!",
902
+ "data": ""
903
+ }
904
+ ```
905
+
906
+ Error (last address):
907
+
908
+ ```json
909
+ {
910
+ "code": 403,
911
+ "message": "At least one address must remain. Address deletion failed!",
912
+ "data": ""
913
+ }
914
+ ```
915
+
916
+ #### Example
917
+
918
+ ```bash
919
+ curl -X DELETE "https://example.com/wp-json/fluent-cart/v2/customers/1/address" \
920
+ -u "username:app_password" \
921
+ -H "Content-Type: application/json" \
922
+ -d '{
923
+ "address": {
924
+ "id": 5
925
+ }
926
+ }'
927
+ ```
928
+
929
+ ---
930
+
931
+ ### Set Primary Address
932
+
933
+ `POST /fluent-cart/v2/customers/{customerId}/address/make-primary`
934
+
935
+ Set a specific address as the primary address for its type. The previous primary address of the same type is automatically demoted.
936
+
937
+ **Permission:** `customers/manage`
938
+
939
+ #### Parameters
940
+
941
+ | Parameter | Type | Location | Required | Description |
942
+ |-----------|------|----------|----------|-------------|
943
+ | `customerId` | integer | path | Yes | The customer ID |
944
+ | `addressId` | integer | body | Yes | The address record ID to make primary |
945
+ | `type` | string | body | Yes | Address type: `billing` or `shipping` |
946
+
947
+ #### Response
948
+
949
+ Success (200):
950
+
951
+ ```json
952
+ {
953
+ "message": "Address successfully set as the primary",
954
+ "data": ""
955
+ }
956
+ ```
957
+
958
+ Error (400):
959
+
960
+ ```json
961
+ {
962
+ "code": 400,
963
+ "message": "Address set as primary failed.",
964
+ "data": ""
965
+ }
966
+ ```
967
+
968
+ #### Example
969
+
970
+ ```bash
971
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/address/make-primary" \
972
+ -u "username:app_password" \
973
+ -H "Content-Type: application/json" \
974
+ -d '{
975
+ "addressId": 5,
976
+ "type": "billing"
977
+ }'
978
+ ```
979
+
980
+ ---
981
+
982
+ ## User Association
983
+
984
+ ### Get Attachable Users
985
+
986
+ `GET /fluent-cart/v2/customers/attachable-user`
987
+
988
+ Retrieve a list of WordPress users that are not yet associated with any FluentCart customer. Useful for linking existing WP users to customer records.
989
+
990
+ **Permission:** `customers/manage`
991
+
992
+ #### Response
993
+
994
+ ```json
995
+ {
996
+ "users": [
997
+ {
998
+ "ID": 10,
999
+ "display_name": "Alice Johnson",
1000
+ "user_email": "alice@example.com"
1001
+ },
1002
+ {
1003
+ "ID": 15,
1004
+ "display_name": "Bob Wilson",
1005
+ "user_email": "bob@example.com"
1006
+ }
1007
+ ]
1008
+ }
1009
+ ```
1010
+
1011
+ #### Example
1012
+
1013
+ ```bash
1014
+ curl -X GET "https://example.com/wp-json/fluent-cart/v2/customers/attachable-user" \
1015
+ -u "username:app_password"
1016
+ ```
1017
+
1018
+ ---
1019
+
1020
+ ### Attach WordPress User
1021
+
1022
+ `POST /fluent-cart/v2/customers/{customerId}/attachable-user`
1023
+
1024
+ Link a WordPress user to an existing customer record. The customer must not already have a linked user, and the target user must not already be linked to another customer.
1025
+
1026
+ **Permission:** `customers/manage`
1027
+
1028
+ #### Parameters
1029
+
1030
+ | Parameter | Type | Location | Required | Description |
1031
+ |-----------|------|----------|----------|-------------|
1032
+ | `customerId` | integer | path | Yes | The customer ID |
1033
+ | `user_id` | integer | body | Yes | The WordPress user ID to attach. Max 50 characters. Must reference an existing user who is not already linked to a customer. |
1034
+
1035
+ #### Response
1036
+
1037
+ Success (200):
1038
+
1039
+ ```json
1040
+ {
1041
+ "message": "User attached successfully"
1042
+ }
1043
+ ```
1044
+
1045
+ Error (customer already has user):
1046
+
1047
+ ```json
1048
+ {
1049
+ "message": "Can not attach user"
1050
+ }
1051
+ ```
1052
+
1053
+ Error (user already linked):
1054
+
1055
+ ```json
1056
+ {
1057
+ "code": "rest_request_validation",
1058
+ "message": "User already linked to a customer."
1059
+ }
1060
+ ```
1061
+
1062
+ Error (user not found):
1063
+
1064
+ ```json
1065
+ {
1066
+ "code": "rest_request_validation",
1067
+ "message": "User not found."
1068
+ }
1069
+ ```
1070
+
1071
+ #### Example
1072
+
1073
+ ```bash
1074
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/attachable-user" \
1075
+ -u "username:app_password" \
1076
+ -H "Content-Type: application/json" \
1077
+ -d '{
1078
+ "user_id": 10
1079
+ }'
1080
+ ```
1081
+
1082
+ ---
1083
+
1084
+ ### Detach WordPress User
1085
+
1086
+ `POST /fluent-cart/v2/customers/{customerId}/detach-user`
1087
+
1088
+ Remove the WordPress user association from a customer record. The customer record itself is preserved; only the `user_id` link is cleared.
1089
+
1090
+ **Permission:** `customers/manage`
1091
+
1092
+ #### Parameters
1093
+
1094
+ | Parameter | Type | Location | Required | Description |
1095
+ |-----------|------|----------|----------|-------------|
1096
+ | `customerId` | integer | path | Yes | The customer ID |
1097
+
1098
+ #### Response
1099
+
1100
+ Success (200):
1101
+
1102
+ ```json
1103
+ {
1104
+ "message": "User detached successfully"
1105
+ }
1106
+ ```
1107
+
1108
+ Error (customer not found):
1109
+
1110
+ ```json
1111
+ {
1112
+ "message": "Customer not found."
1113
+ }
1114
+ ```
1115
+
1116
+ #### Example
1117
+
1118
+ ```bash
1119
+ curl -X POST "https://example.com/wp-json/fluent-cart/v2/customers/1/detach-user" \
1120
+ -u "username:app_password"
1121
+ ```