=== TELO Affiliates Lite ===
Contributors: miguelqagencia, grupoqagencia
Tags: affiliates, woocommerce, referral, commission, payouts, shortcode, affiliate-dashboard
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 3.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lightweight affiliate management for WooCommerce: unique link with parameter, affiliate dashboard via shortcode, payout requests, public pages per affiliate, JSON import/export and more.

== Description ==

**TELO Affiliates** adds a lightweight affiliate layer on top of WooCommerce without heavy dependencies. Ideal if you want to:

- Create a **unique link** for each affiliate (with configurable URL parameter) and track associated orders.
- Show each affiliate their **dashboard** with sales, commissions and **payout request** via **shortcode**.
- Manage **payouts**: mark commissions as paid (with history) or approve payout requests sent from the affiliate dashboard.
- Create **public pages** per affiliate (`/panel-afiliado/{slug}`) with a dedicated template, **no header/sidebars**, and forced **noindex/nofollow**.
- **Import/Export** your affiliates in **JSON** (slug, name and commission % only).
- Use admin tables based on **WP_List_Table** with search, sorting and pagination.

### Features

- **Shortcode**: `[telo_affiliate_dashboard slug="juan"]`
  - Unique link with tracking parameter (set it with the `TELO_AFF_PARAM` constant).
  - Historical summary: sales, total amount and total commission.
  - Pending: base and commission still pending payout.
  - **“Request payout” button** with minimum threshold (filter).
  - Payout history.
  - Accessible and ready for custom styles (wrapper class).

- **Admin → Affiliates**
  - Add/edit/delete affiliates (name, slug, commission %).
  - **Import/Export** JSON (slug, name, rate only; no sales or history).
  - Table with search/sorting/pagination.
  - **Mark paid** (moves affiliate orders to payout history).
  - “Affiliate” column in the order list (HPOS and classic list).

- **Admin → Affiliate Pages**
  - List of all affiliates with the status of their **public page**.
  - **Create page** per affiliate (`/panel-afiliado/{slug}`) with template `telo-affiliates/affiliate-page.php`.
  - **Copy URL**, open, **move to trash**, **restore** or **permanently delete** (plugin-created pages only).
  - Own “Trash” view + “Empty trash” button.

- **Admin → Payout Requests**
  - Responsive list with collapsible orders (chips) per request.
  - **Approve** (marks orders as paid and creates record in history) or **reject** (with note).
  - Notices and status control: pending, approved, rejected, no orders.

- **SEO & UX**
  - Affiliate pages are forced **noindex/nofollow** (compatible with Yoast SEO and Rank Math).
  - Crawling of `/panel-afiliado/` is discouraged in `robots.txt`.
  - Dedicated template without header/sidebars and wrapper `.telo-aff-page` for your global styles.

### Hooks

- **Filters**
  - `telo_affiliates_min_payout` (float, default `20.0`): minimum commission required to allow “Request payout”.

- **Actions**
  - `telo_affiliates_payout_recorded( $payout_id, $slug, $order_ids, $amount )`: fires when a payout is recorded.

### Order Meta Stored

- `_telo_affiliate` — affiliate slug.
- `_telo_aff_paid` — `yes` if marked as paid.
- `_telo_aff_payout_id` — ID of the recorded payout.
- `_telo_aff_paid_ts` — timestamp of the payout.

### Shortcode

[telo_affiliate_dashboard slug="juan"]

Renders “Juan’s” dashboard with:
- Unique link (use the `TELO_AFF_PARAM` constant to change the parameter name).
- Historical and pending summary.
- **Request payout** button (respects the minimum configured via filter).
- Responsive **history table** (CSS-ready classes).

== Installation ==

1. Upload the plugin to the `/wp-content/plugins/` directory or install it from the WordPress.org repository.
2. Activate it in *Plugins → Installed Plugins*.
3. (Optional) Define the `TELO_AFF_PARAM` constant if you want to change the tracking parameter name (for example `ref`):
   ```php
   define( 'TELO_AFF_PARAM', 'ref' );
4. Go to Affiliates to create your affiliates (name, slug, %).
5. Create public pages from Affiliates → Affiliate Pages (“Create Page” button).
6. Insert the affiliate dashboard wherever you want with the shortcode:
[telo_affiliate_dashboard slug="your_slug"]

== Frequently Asked Questions ==

= Which URL parameter is used for tracking? =
It is configurable via the TELO_AFF_PARAM constant (define it in wp-config.php or in the plugin/theme bootstrap). If you do not define it, the plugin’s default is used.

= Does import affect sales or historical payout data? =
No. Import/export only handles slug, name and rate. No orders, commissions or historical data.

= Do affiliate pages affect my SEO? =
No. They are created with a dedicated template without header/sidebars, marked noindex/nofollow and /panel-afiliado/ is disallowed in robots.txt.

= Can I customize styles? =
Yes. The shortcode and template use wrapper classes (.telo-aff-frontend, .telo-aff-page, etc.). Add your CSS in your theme or in a plugin stylesheet.

= Does it work with WooCommerce HPOS? =
Yes. The “Affiliate” column is added to the order list in both classic and HPOS views.

== Screenshots ==

1. Main Affiliates screen with table and actions.
2. Affiliate Pages submenu with creation, URL copy and trash.
3. Payout Requests with collapsible orders and approve/reject actions.
4. Front-end affiliate dashboard with summary and history.

== Changelog ==

= 3.0.1 =
 - Minor fixes based on the WordPress.org plugin review (security hardening and compatibility tweaks).

= 3.0.0 =
 - Initial version.
 - Affiliate dashboard shortcode.
 - Payout requests with approval/rejection.
 - Payout history.
 - “Affiliate Pages” submenu with create/restore/trash.
 - Import/Export affiliates in JSON.
 - “Affiliate” column in orders (classic and HPOS).
 - Noindex/nofollow for affiliate pages and Disallow entry in robots.txt.
 - Responsive tables in front end and admin.

== Upgrade Notice ==

= 3.0.0 =
First public version.

== Privacy ==

This plugin stores metadata in orders (affiliate association and payout status) and, optionally, affiliate contact data (name, email). Make sure to reflect this in your privacy policy if needed.

== External Services ==

This plugin can optionally connect to the licensing service to activate PRO features:

licencias.qagencia.com — License validation and update checks for the PRO add-on.
Data sent: site URL, WordPress version, plugin version, license key (hashed) and server IP.
Frequency: on manual activation/deactivation and via a periodic check (daily).
Privacy: https://licencias.qagencia.com/privacy

Terms: https://licencias.qagencia.com/terms