# Woo Thank You Widget

> Customisable order-received / thank-you page widget. Replaces WC's default `checkout/thankyou.php` template with Elementor-rendered content. 3 layout presets (note: preset-1 file has typo `perest-1.php`).

**Class file:** `includes/Elements/Woo_Thank_You.php` (3,335 lines)
**Slug:** `woo-thank-you` (widget id `eael-woo-thank-you`)
**Public docs:** <https://essential-addons.com/elementor/docs/ea-woo-thank-you>
**Pro-shared:** Pro-only. **Requires WooCommerce + order-received endpoint context.**

## Overview

Replaces WC's `checkout/thankyou.php` template via a runtime `wc_get_template` filter when the widget is present on the current page AND the user is on the `order-received` endpoint. Renders order summary, payment method, customer details, billing/shipping addresses, downloads (if applicable). 3 layout presets (preset-1, preset-2, preset-3) — note: preset-1's template file is misspelled `perest-1.php` in the repo. Constructor-level hook is the distinctive piece — most Pro widgets don't override WC templates wholesale.

## Pro vs Lite

Pro-only.

## File Map

| File | Role |
| --- | --- |
| `includes/Elements/Woo_Thank_You.php` | Widget class (3,335 lines) — constructor registers WC template filter |
| `includes/Template/Woo-Thank-You/perest-1.php` ⚠ | Preset 1 (**filename typo: "perest" not "preset"**) |
| `includes/Template/Woo-Thank-You/preset-2.php` | Preset 2 |
| `includes/Template/Woo-Thank-You/preset-3.php` | Preset 3 |
| `src/css/view/woo-thank-you.scss` → `assets/front-end/css/view/woo-thank-you.min.css` | Per-preset styling |
| `config.php` entry `'woo-thank-you'` | Self CSS only (no JS) |

## Architecture

- **Constructor-registered `wc_get_template` filter** (line 36-46) — runs only when:
  - `is_wc_endpoint_url('order-received')` is true (visitor is on the thank-you page)
  - The widget appears in the current post's saved widget list (checked via `_elementor_controls_usage` OR `_eael_widget_elements` post meta)
  - When both conditions met, Pro returns `EAEL_PLUGIN_PATH . 'index.php'` instead of WC's `checkout/thankyou.php` — **effectively replacing WC's thank-you with an empty placeholder** so Elementor's render takes over.
- **Dual widget-meta lookup** — Pro checks **two** post-meta keys (`_elementor_controls_usage` from Elementor 3.x+, `_eael_widget_elements` from EA's older legacy). Uses whichever exists. Backwards-compat for plugins / sites running older EA versions.
- **`EAEL_PLUGIN_PATH . 'index.php'` as no-op template** — Pro doesn't ship a literal "empty" template; it points to Lite's `index.php` which is a stub. **Constraint:** if Lite's `index.php` ever contains code, the override breaks. Fragile.
- **Custom `EAEL_Background` control** imported at line 11 — Pro-owned control type (`Essential_Addons_Elementor\Controls\EAEL_Background`). Verify the control class exists in Pro's `includes/Controls/`.
- **No `class_exists('WooCommerce')` direct check** — `is_wc_endpoint_url` function check guards the constructor branch.
- **`perest-1.php` template typo** preserved — renaming would break older saved pages where the user picked "preset-1" (saved string matches the misspelled file via the template-resolver).

## Render Output (preset-1 — high level)

```html
<div class="eael-woo-thank-you eael-woo-thank-you-preset-1">
  <div class="eael-thank-you-header">
    [?] <span class="success-icon"></span>
    <h2>Thank you for your order, {first_name}!</h2>
    <p>Your order #{order_id} has been received.</p>
  </div>
  <div class="eael-order-summary">
    <h3>Order Details</h3>
    <table>
      <tr><th>Order Number</th><td>{order_id}</td></tr>
      <tr><th>Date</th><td>{date}</td></tr>
      <tr><th>Total</th><td>{total}</td></tr>
      <tr><th>Payment Method</th><td>{payment_method}</td></tr>
    </table>
  </div>
  <div class="eael-order-items">
    <!-- Line items -->
  </div>
  <div class="eael-billing-shipping">
    <div class="billing">{billing_address}</div>
    <div class="shipping">{shipping_address}</div>
  </div>
  [?] <div class="eael-downloads">{download links if order has downloadable products}</div>
</div>
```

## Controls Reference

| Control id | Tab → Section | Type | Purpose |
| --- | --- | --- | --- |
| Layout preset | Content → Layout | SELECT | `perest-1` (typo preserved) / `preset-2` / `preset-3` |
| Header text / icon | Content → Header | TEXT / ICONS | Thank-you message + success icon |
| Order summary visibility (date, items, payment, etc.) | Content → Sections | SWITCHER | Per-section toggles |
| Billing / shipping toggle | Content → Sections | SWITCHER | Show addresses |
| Downloads section | Content → Sections | SWITCHER | Show downloadable items |
| `EAEL_Background` for hero section | Style → Header | EAEL_Background | Pro custom background control |
| Typography / spacing / colors (per preset) | Style → ... | various | Per-preset styling |

## Conditional Dependencies

Per-preset gating (similar to Woo_Account_Dashboard) — control visibility tied to selected layout.

## JavaScript Lifecycle

N/A — no JS source file. Pure server-rendered.

## Hooks & Filters

### WC hooks consumed

| Hook | Where | Purpose |
| --- | --- | --- |
| `wc_get_template` filter | line 38 | Overrides `checkout/thankyou.php` to `EAEL_PLUGIN_PATH/index.php` (no-op) so Pro can render via Elementor |
| `is_wc_endpoint_url('order-received')` | line 36 | Endpoint gate |

### Pro / EA hooks emitted

None directly.

## Common Issues

| Symptom | Likely cause | Diagnose | Fix |
| --- | --- | --- | --- |
| WC's default thank-you renders instead of Pro | Page not detected as containing the widget | Inspect `_elementor_controls_usage` post meta | Save the page in Elementor; verify widget appears in the saved meta |
| Empty page at `/order-received/...` | `EAEL_PLUGIN_PATH . 'index.php'` no longer empty | Read Lite's `index.php` | Override breaks if Lite changes `index.php`; fragile |
| Order details missing | Order object not loaded — wrong endpoint | Confirm URL is `order-received/{id}/?key=...` | Standard WC flow; not Pro's bug |
| Custom `EAEL_Background` control errors | `Essential_Addons_Elementor\Controls\EAEL_Background` not registered | Check Lite's control registration | Verify Lite version supports this control |
| Preset-1 selector doesn't apply | Filename typo `perest-1.php` | Pro's resolver matches the typo; CSS class is `eael-woo-thank-you-perest-1`? | Verify CSS rules match the saved selector |

## Known Limitations

- **`perest-1.php` filename typo** — frozen in user content; cannot rename without migration
- **`EAEL_PLUGIN_PATH . 'index.php'` as no-op override** — fragile dependency on Lite's stub file
- **Constructor-level template filter** — runs for every page-render where this widget exists; minor perf cost
- **Dual widget-meta key lookup** for backwards compat — code smell; sunset older `_eael_widget_elements` key in a future version
- **No fallback** if the WC order is invalid / missing — relies on WC to handle
- **Custom `EAEL_Background` control** is Pro-only — referenced but not documented widely; verify its class path
- **3,335 lines** — per-preset control bloat

## Cross-References

- Sibling: [`woo-account-dashboard.md`](woo-account-dashboard.md), [`woo-product-slider.md`](woo-product-slider.md), [`woo-cross-sells.md`](woo-cross-sells.md)
- Shared patterns: [`_patterns.md`](_patterns.md)
