chore: batch supporting UI, settings schema, templates, and docs updates

This commit is contained in:
Dwindi Ramadhana
2026-06-01 00:58:43 +07:00
parent 30f2fc2ea6
commit f3c4ee7124
20 changed files with 1149 additions and 54 deletions

View File

@@ -231,29 +231,41 @@ Referral tracking and commission management system.
#### 1. Database Tables
```sql
wp_woonoow_affiliates (id, user_id, referral_code, commission_rate, status, total_referrals, total_earnings, paid_earnings)
wp_woonoow_referrals (id, affiliate_id, order_id, customer_id, commission_amount, status, created_at, approved_at, paid_at)
wp_woonoow_affiliate_payouts (id, affiliate_id, amount, method, status, notes, created_at, completed_at)
wp_woonoow_affiliates (id, user_id, referral_code, coupon_id, commission_rate, status, total_referrals, total_earnings, paid_earnings)
wp_woonoow_referrals (id, affiliate_id, order_id, customer_id, commission_amount, currency, status, created_at, approved_at, paid_at)
wp_woonoow_affiliate_payouts (id, affiliate_id, amount, currency, method, status, notes, created_at, completed_at)
```
#### 2. Tracking System
```php
class AffiliateTracker {
// Set cookie for 30 days
// Set secure cookie for 30 days (SameSite=Lax)
public function track_referral($referral_code) {
setcookie('woonoow_ref', $referral_code, time() + (30 * DAY_IN_SECONDS));
// Must check WooCommerce cookie consent first
$options = [
'expires' => time() + (30 * DAY_IN_SECONDS),
'path' => '/',
'secure' => is_ssl(),
'samesite' => 'Lax'
];
setcookie('woonoow_ref', $referral_code, $options);
}
// Record on order completion
// Record as 'pending' on order creation/payment
public function record_referral($order_id) {
if (isset($_COOKIE['woonoow_ref'])) {
// Get affiliate by code
// Calculate commission
// Create referral record
// Clear cookie
if (isset($_COOKIE['woonoow_ref']) || $this->has_affiliate_coupon($order_id)) {
// Get affiliate by code or coupon
// Calculate commission (on subtotal, excluding tax/shipping)
// Create referral record with 'pending' status
// ActionScheduler: Schedule auto-approval in 14 days
}
}
// Handle order refunds/cancellations
public function handle_order_refund($order_id) {
// Cancel/revert pending referral
}
}
```
@@ -275,8 +287,9 @@ class AffiliateTracker {
#### 5. Notification Events
- `affiliate_application_approved`
- `affiliate_referral_completed`
- `affiliate_referral_received` (Pending Approval)
- `affiliate_payout_processed`
- `affiliate_threshold_reached` (Admin Alert)
### Priority: **Medium** 🟡
### Effort: 3-4 weeks