=== Personalize My Order ===
Contributors: jsjack74
Tags: woocommerce, customization, personalize, order-customization, product-customization
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 8.0
WC requires at least: 7.0
WC tested up to: 10.8
Stable tag: 1.0.0
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Collect product customization data after order placement via a secure tokenized URL. Supports custom fields, local file uploads, partial saves, and per-item completion tracking.

== Description ==

Personalize My Order lets you collect product customization details from customers *after* they place an order — without blocking the checkout flow.

Once an order is paid, the customer receives a secure, time-limited link by email. They visit a dedicated customization page on your store, fill in the fields you've configured for each product, and submit. You see everything neatly displayed on the WooCommerce order detail page.

**Key features:**

* Secure tokenized URLs — HMAC-SHA256 signed, time-limited (configurable expiry), works for both guests and logged-in customers
* Per-product custom fields — configure different fields for each product, or set global fallback fields that apply to all products
* 13 field types — text, textarea, select, radio, checkbox, file, number, email, URL, date, color, range, and tel
* Local file uploads — uploaded files are stored securely in your WordPress uploads directory (`wp-content/uploads/persmyor-uploads/`); directory listing is blocked via `.htaccess`
* Partial saves / autosave — customers can save a draft and come back later; the form autosaves on tab close
* Per-item completion tracking — each order item is tracked independently as pending, partial, or complete
* Admin display — submitted values shown inline on the order detail page, with a dedicated meta box and a status column on the orders list
* My Account integration — customers can review and complete pending customizations from their My Account page
* Developer hooks — filter fields per product or act when an order is fully customized

== Installation ==

1. Upload the `personalize-my-order` folder to `/wp-content/plugins/`.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. WooCommerce must be active — the plugin will show an admin notice if it isn't.
4. On activation, a **Order Customization** page is created automatically with the `[persmyor_customization_form]` shortcode. Do not delete this page.
5. Go to **WooCommerce → Settings → Personalize My Order** to configure the plugin.

== Configuration ==

= General =

* **Token expiry** — number of days before the customization link expires (default: 30)
* **Send email on order** — toggle the customization email sent to the customer after payment

= Global fields =

Define fallback fields that apply to all products that don't have their own field configuration. Use the drag-and-drop field builder to add, reorder, and remove fields.

= Per-product fields =

On any product edit page, a **Customization Fields** meta box lets you configure fields specific to that product. These take priority over global fields.

== Field types ==

The following field types are supported in the field builder:

* **text** — single-line text input
* **textarea** — multi-line text input
* **select** — dropdown with predefined options
* **radio** — radio button group
* **checkbox** — single checkbox or multi-checkbox group
* **file** — file upload (stored in your server's uploads directory); supports `accept` (MIME types) and `max_size` (in MB)
* **number** — numeric input; supports `min`, `max`, `step`
* **email** — email address with format validation
* **url** — URL with format validation
* **date** — date picker
* **color** — color picker
* **range** — range slider; supports `min`, `max`, `step`
* **tel** — telephone number input

== How it works ==

1. Customer places an order on your WooCommerce store.
2. A secure HMAC-signed token is generated and stored against the order.
3. After payment, the customer receives an email with a unique customization link (also appended to standard WooCommerce customer emails).
4. The customer opens the link, fills in the form for each ordered product, and submits.
5. Submitted values are saved as WooCommerce order item meta.
6. The admin sees the customization data on the order detail page, along with uploaded file links and a completion status badge.
7. When all items are complete, an order note is added and the `persmyor_order_fully_customized` action fires.

== Developer hooks ==

= Filters =

**`persmyor_product_fields`**
Modify the resolved field definitions for a product before the form is rendered or data is validated.

    add_filter( 'persmyor_product_fields', function( $fields, $product_id, $product ) {
        // Add, remove, or modify fields
        return $fields;
    }, 10, 3 );

= Actions =

**`persmyor_order_fully_customized`**
Fires when every customizable item in an order has been submitted with status `complete`. Receives the `WC_Order` object.


    add_action( 'persmyor_order_fully_customized', function( $order ) {
        // e.g. trigger production workflow
    } );


== Frequently Asked Questions ==

= Does the plugin work for guest customers? =
Yes. The tokenized URL is emailed to the billing address and works without requiring the customer to log in.

= What happens if the customer doesn't complete customization? =
The order item stays in `pending` or `partial` status. You can see incomplete items in the orders list column and on the order detail page. The customer can return to the customization page at any time before the token expires.

= Can I set different fields for different products? =
Yes. Add fields via the **Customization Fields** meta box on each product edit page. Products without their own fields fall back to the global fields configured in settings.

= Where are uploaded files stored? =
Files are stored on your own server at `wp-content/uploads/persmyor-uploads/{order_id}_{customer_name}/{product_name}/`. The directory is protected with an `.htaccess` file and an `index.php` stub to prevent direct browsing.

= Can I change the customization page? =
Yes. Go to **WooCommerce → Settings → Personalize My Order → Customization Page** and choose any published page that contains the `[persmyor_customization_form]` shortcode.

= What database tables does the plugin create? =
Two custom tables are created on activation:
- `{prefix}persmyor_item_submissions` — tracks per-item submission status and timestamps
- `{prefix}persmyor_uploaded_files` — logs uploaded file metadata and local URLs


== Screenshots ==

1. Customization form as seen by the customer — tabbed per order item
2. Admin order detail page showing submitted customization data and file links
3. WooCommerce orders list with customization status column
4. Settings page — general and appearance options
5. Per-product field builder meta box on the product edit page
6. My Account — customer's customization overview tab

== Changelog ==

= 1.0.0 =
Initial release — no upgrade steps required.