=== Factorize Portal ===
Contributors: webyoungstown
Tags: woocommerce, login, registration, account, user-experience
Requires at least: 6.2
Tested up to: 6.7
Stable tag: 1.0.1
Requires PHP: 7.4
License: Factorize License (proprietary)
License URI: https://factorize.webyoungstown.com/license/

One-form sign-in for WooCommerce: email first, then password for existing accounts or instant account creation, plus an optional phone field.

== Description ==

The logged-out WooCommerce My Account page greets every visitor with two stacked forms — Login and Register — and makes them decide up front which one they are. Most shoppers do not remember whether they already have an account with your store, so they guess wrong, hit an error, and give up. Factorize Portal replaces that fork with a single flow: type your email, press Continue, and the page figures out the rest. Existing customers see the password field and log in; new visitors set a password (and, optionally, a phone number) and get an account on the spot — all through WooCommerce's own forms, nonces, and server-side validation.

= Features =

* **Email-first sign-in panel** — the logged-out My Account page shows one email box and one Continue button instead of stacked Login and Register forms.
* **Live account lookup** — a nonce-protected AJAX call checks whether the typed email (or username) already has an account. The check runs entirely on your own server.
* **Existing account, log in** — the password field, "Remember me" checkbox, and "Lost your password?" link appear, and the real WooCommerce login form submits exactly as it always has.
* **New visitor, instant registration** — the panel flips to create-account mode with a clear "No account found for you@example.com" message; the typed email and password are carried into WooCommerce's real (hidden) registration form and submitted, so every registration hook, nonce, and server-side check still runs.
* **Optional phone number at sign-up** — collected right in the create-account step and on the classic registration form ("Used for pickup-ready and auction alerts"), format-validated only when a number is actually provided, and saved to the standard `billing_phone` user meta that WooCommerce uses for billing details.
* **Progressive enhancement, not replacement** — visitors without JavaScript get the untouched classic two-form page, and if the lookup request ever fails the panel falls back to the standard login form and reveals the register form again. Nobody gets locked out.
* **Featherweight footprint** — one small dependency-free script (no jQuery), enqueued only on the logged-out account page and cache-busted by file modification time. Nothing loads anywhere else.
* **Factorize hub card** — registers itself under the Customers tab of the shared Factorize admin hub with a live status line showing whether the phone field is on.
* **Legacy-friendly configuration** — reads the `factorize-portal_options` option, still honors a pre-rename `empire-account-portal_options` row, and passes the merged result through a filter for code-level overrides.
* **Clean uninstall** — deleting the plugin removes only its own option rows; customer accounts and saved phone numbers are never touched.

= Works standalone, better together =

Factorize is a modular WooCommerce toolkit for liquidation, bin, discount, and open-box stores, built and battle-tested on a real 950-product store. Every plugin works completely standalone; any of them alone stands up the shared "Factorize" admin hub, and together they fill it with category tabs (Insights / Selling / Customers / Storefront). Factorize Portal on its own creates the hub and adds its card to the Customers tab.

= Configuration =

There is deliberately no settings screen — one option array and one filter control everything:

* `phone_field_enabled` (default `true`) — when true, the optional phone field renders on the WooCommerce registration form, its format is validated whenever a number is provided, and the value is saved to `billing_phone` on account creation. Set it to false to switch all three behaviors off.

Values are read from the `factorize-portal_options` option (an array merged over the defaults; a legacy `empire-account-portal_options` row is honored as a fallback), and the merged result passes through the `factorize-portal_config` filter — so either a database option or one line of code can override any key.

= Roadmap =

Planned for future releases — none of these ship in 1.0.0 yet:

* Google / Apple one-tap sign-in
* Magic-link login
* SMS one-time codes
* Passkey support
* Profile completeness nudges

== Installation ==

1. Upload the `factorize-portal` folder to `/wp-content/plugins/`, or install it through the WordPress admin, then activate it. WooCommerce must be active for anything visible to happen.
2. In WooCommerce → Settings → Accounts & Privacy, make sure "Allow customers to create an account on the 'My account' page" is enabled — the portal drives WooCommerce's real registration form, so that form needs to exist on the page.
3. Log out (or open a private window) and visit the My Account page: the two stacked forms are now one email-first panel. There are no credentials or API keys to enter.
4. In the admin sidebar you will find the new Factorize menu (visible to shop managers and administrators). The Portal card sits under the Customers tab and shows whether the phone field is on.
5. Optional: to turn the registration phone field off, set the option from WP-CLI — `wp option update factorize-portal_options '{"phone_field_enabled":false}' --format=json` — or hook the `factorize-portal_config` filter from a small plugin or your child theme.

== Frequently Asked Questions ==

= Does it work without the other Factorize plugins? =

Yes. Factorize Portal is completely standalone — it calls no functions from sibling plugins and none call into it. On its own it also stands up the full Factorize admin hub with its one Customers tab. It does require WooCommerce: without it the plugin loads but does nothing visible.

= Does it replace WooCommerce's login or registration logic? =

No. It is a progressive-enhancement layer over WooCommerce's real login and register forms. The email lookup only decides which of the two real forms to submit; nonces, registration hooks, and all server-side validation run untouched. Visitors without JavaScript get the classic two-form page.

= Does any data leave my server? =

No. The only network request the portal makes is the browser's AJAX call to your own site's admin-ajax.php to check whether an account exists. Phone numbers are stored in the standard `billing_phone` user meta in your own database; the plugin creates no custom tables and calls no external services.

= What happens if the account lookup fails? =

The panel falls back to the standard login form and reveals the register form again, so the page always remains usable — a failed AJAX call can never lock a customer out.

= How do I disable the phone field? =

Set `phone_field_enabled` to false, either via the `factorize-portal_options` option (for example with WP-CLI: `wp option update factorize-portal_options '{"phone_field_enabled":false}' --format=json`) or via the `factorize-portal_config` filter. That disables the field, its validation, and the meta save in one switch.

= Why does the portal look unstyled on my theme? =

By design the plugin ships no CSS — its et-portal classes are meant to be styled by your theme (the suite's companion theme carries the reference styles). The flow works on any theme; it just looks plain until you add a few style rules.

== Screenshots ==

1. The logged-out My Account page as a single panel: one email field and a Continue button.
2. Existing account detected — the password field, "Remember me", and "Lost your password?" appear with a Log in button.
3. New email — the panel flips to create-account mode: a "No account found" message, the password field, and the optional phone input above a Create account button.
4. The Factorize admin hub, Customers tab, showing the Factorize Portal card with its phone-field status line.
5. The classic WooCommerce registration form with the optional phone-number field — what no-JS visitors see.

== Changelog ==

= 1.0.0 =
* Initial release.
* Email-first sign-in panel replacing the stacked login and register forms on the logged-out My Account page.
* Nonce-protected AJAX account lookup with automatic switching between log-in and create-account modes.
* Instant registration through WooCommerce's real form — hooks, nonces, and server-side validation untouched.
* Optional, format-validated phone-number field at registration, saved to `billing_phone` user meta.
* Shared Factorize admin hub with the Portal status card under the Customers tab.
* Clean uninstall that removes only the plugin's own options.
