=== OCW Checkout Logic for WooCommerce ===
Contributors: adviespraktijkocw
Author URI: https://onlinecursuswebsites.nl
Tags: woocommerce, checkout, fields, product, required fields
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 8.0
WC requires at least: 6.0
WC tested up to: 10.8
Stable tag: 2.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Control per product which WooCommerce checkout fields are required, optional or hidden. Independent add-on, not affiliated with Automattic, Inc.

== Description ==

OCW Checkout Logic for WooCommerce lets you control per product whether each WooCommerce checkout field is required, optional or hidden. When the cart contains multiple products, the strictest rule wins automatically.

> ⚠ **Independent third-party add-on.** This plugin is developed and maintained entirely by Adviespraktijk OCW. It is not affiliated with or endorsed by Automattic, Inc. "WooCommerce" is a trademark of Automattic, Inc., used here purely to describe what this add-on integrates with.

> ⚠ **Requires WooCommerce.** The plugin filters WooCommerce checkout fields. Without WooCommerce active, the plugin has nothing to operate on — WordPress refuses to activate it via the `Requires Plugins: woocommerce` header.

= Free features =

* Set each WooCommerce checkout field per product to: Required, Optional, Hidden or Default
* Works for billing, shipping and order-notes fields (21 standard Woo fields covered)
* Multi-product cart: strictest rule wins (Required > Optional > Hidden > Default)
* Quick actions: set all fields with a single click
* HPOS (High-Performance Order Storage) compatible
* Cart & Checkout Blocks compatible
* Tutorial submenu with progress detection — auto-opens on activation
* Clean OCW house-style admin UI (teal / navy / pink)

= PRO features =

* **Custom fields per product** — add text, email, phone, textarea, dropdown or checkbox fields beyond Woo's standard set. Saved as order item meta, automatically visible in admin order screen + customer emails.
* **Conditional logic** — "show field X when field Y equals value Z". Lightweight JS rule engine on the checkout, no flicker.
* **Per-category settings** — configure checkout rules for an entire product category. Per-product overrides still win, category fills the gaps.
* **Field validation patterns** — built-in presets (Dutch postcode, KVK 8-digit, EU VAT, IBAN, Dutch phone) or your own regex. Runs server-side on `woocommerce_checkout_process`.
* **Configuration templates** — save the full checkout-fields configuration of a product as a named template (standard field statuses, custom fields, conditional logic, validation rules) and apply it to any other product in one click. Manage all templates from a dedicated submenu.
* **Automatic updates** via the OCW License Server.
* **Priority support** from Onne at OCW.

PRO is sold separately at [onlinecursuswebsites.nl/ocw-checkout-logic-pro](https://onlinecursuswebsites.nl/ocw-checkout-logic-pro).

= Typical use cases =

* **Digital products** — hide all shipping fields, keep only email and name
* **B2B products** — make company name required, add a VAT-number field (PRO)
* **Gift cards** — hide address fields, make order notes required
* **Event tickets** — hide shipping, require phone, validate it (PRO)

= Requirements =

* WordPress 6.0 or higher
* WooCommerce 6.0 or higher
* PHP 8.0 or higher

== Installation ==

1. Upload the `ocw-checkout-logic` folder to `/wp-content/plugins/`
2. Activate the plugin via the **Plugins** menu in WordPress
3. The Tutorial page opens automatically — follow the 4 steps
4. To configure a product: open the product, go to the **Checkout fields** tab

== Frequently Asked Questions ==

= Is this an official WooCommerce plugin? =
No. This is an independent third-party add-on developed and maintained by Adviespraktijk OCW. It is not affiliated with or endorsed by Automattic, Inc. "WooCommerce" is a trademark of Automattic, Inc., used here purely to describe what this add-on integrates with.

= Does this work with multiple products in the cart? =
Yes. The plugin applies the strictest rule: Required wins over Optional, which wins over Hidden, which wins over Default.

= Can I add custom fields beyond Woo's standard set? =
Yes — that is one of the PRO features. The free version only configures the 21 standard Woo checkout fields.

= Does it work with the WooCommerce Checkout Block? =
The free field control (required / optional / hidden per product) works on both the classic checkout and the Cart & Checkout Blocks, including server-side enforcement on the Blocks (Store API) route. The PRO features custom fields, conditional logic and validation patterns currently apply to the classic checkout shortcode only.

= Is it HPOS-compatible? =
Yes, fully compatible with WooCommerce High-Performance Order Storage.

= Do extra database queries run on the checkout page? =
No. Settings are cached in the WordPress object cache.

= How does the PRO license work? =
After purchase you receive a license key by email. Paste it in **Checkout Fields → License & PRO**. All PRO features unlock immediately, automatic updates start flowing through the OCW License Server.

== Screenshots ==

1. "Checkout fields" tab on the product edit screen
2. Tutorial submenu with progress detection
3. License & PRO submenu with feature grid
4. Checkout with product-specific field configuration

== Changelog ==

= 2.4.0 =
* **Blocks checkout: real server-side field handling.** Hidden/optional fields are now relaxed via the `woocommerce_get_country_locale` filter (drives both the Store API and the React client validation), and per-product required fields are enforced server-side on the Store API checkout route. Previously, hidden required fields on the Blocks checkout were worked around by injecting a space character into the input — which wrote junk into order address data. That hack is removed.
* Hidden fields are blanked on Blocks orders (autofill could still populate a field the shopper never saw). Country and email are never blanked — they drive tax/shipping totals and the order confirmation.
* New `uninstall.php` — removes all plugin options, transients, product/category/user meta and cron events on deletion. Order item meta (custom field values) is deliberately preserved as part of order history.
* Generated `languages/ocw-checkout-logic.pot` (96 strings) — the languages folder previously shipped without a template.
* PRO validation errors now show the field label instead of the raw field key (e.g. "Postcode" instead of "billing_postcode").
* Product-page bulk-action strings (confirm/notification) are now translatable via `wp_localize_script` — they were hardcoded Dutch.
* Classic checkout required-field error message translated to English source text per i18n policy.
* readme.txt: short description trimmed to the 150-char limit, stale "WooCommerce → Checkout Fields License" menu path corrected to "Checkout Fields → License & PRO", honest Blocks-support scoping in the FAQ (PRO custom fields / conditional logic / validation are classic-checkout only).
* Compatibility: `Tested up to: 7.0`, `WC tested up to: 10.8`.

= 2.3.0 =
* **Renamed from "Checkout Fields for Woo" to "OCW Checkout Logic for WooCommerce"** following WordPress.org plugin-directory naming review — the new name leads with a distinctive identifier (OCW) and places the trademark "WooCommerce" at the end after "for", as required by the trademark guidelines.
* New slug: `ocw-checkout-logic`. New text domain: `ocw-checkout-logic`.
* All internal `WCPCF_*`, `WC_Product_Checkout_Fields` and `CFFW_*` symbols renamed to `OCWCL_*` — eliminates the reserved `wc_` prefix flagged by the plugin reviewer.
* Added `Requires Plugins: woocommerce` header so WordPress now checks for WooCommerce automatically before activating.
* Removed the manual `load_plugin_textdomain()` call — WordPress.org auto-loads translations from the plugin slug since WP 4.6.
* Independent-add-on disclaimer now visible in the plugin header description, the Plugins-list row meta, the readme.txt short description, the Description prologue, the FAQ, and the Tutorial / License & PRO / Field order page headers — to make the unaffiliated status unambiguous on every surface.

= 2.2.3 =
* WordPress.org plugin-directory readiness:
  * Added `License: GPLv2 or later` and `License URI: https://www.gnu.org/licenses/gpl-2.0.html` headers to the main plugin file (scanner flagged `plugin_header_no_license`).
  * Synced license format between plugin header and `readme.txt` — both now say `GPLv2 or later` (was `GPL v2 or later` in readme, missing in header). Fixes `license_mismatch`.
  * Bumped `Tested up to` from 6.8 to 6.9 in both plugin header and readme. Fixes `outdated_tested_upto_header`.
  * Added `languages/index.php` placeholder so the `Domain Path: /languages` header points to an existing folder. Fixes `plugin_header_nonexistent_domain_path`.

= 2.2.2 =
* **Fix: Hidden status now also works on builder-rendered checkout pages.** In 2.2.1 the wrapper-hide CSS was only injected on Woo's officially-configured Checkout page (`is_checkout()` returned true). Many sites place the Woo checkout form somewhere else via a page builder — Elementor's WooCommerce Checkout widget on the cart page is the textbook case. On those pages our CSS never loaded, so the labels stayed visible. The `is_checkout()` gate is removed; the rule (`.ocwcl-hidden-field { display: none !important; }`) is now injected on every front-end page. Safe because the class only ever exists where our filter has already done its work.
* Blocks checkout: same gate-widening — `inject_blocks_checkout_css` now runs on both cart and checkout pages so Blocks-on-cart-page setups are covered too.

= 2.2.1 =
* **Fix: Hidden status now actually hides the field row** at checkout. Previously the input was hidden but its label stayed visible — labels like "Country / Region (optional)" or "Street address" still showed up because no CSS rule was hiding the wrapper. Fixed by injecting one inline CSS rule `.ocwcl-hidden-field { display: none !important; }` on every checkout page. Works for the classic shortcode checkout, Elementor's WooCommerce Checkout widget and any other widget/builder that renders fields through `woocommerce_form_field()`.
* Cleaned up the now-redundant inline `display:none` style that was attached to each hidden input — the wrapper CSS makes it obsolete.

= 2.2.0 =
* **Site-wide checkout field order** (free) — new `Checkout Fields → Field order` submenu lets you drag the 21 standard Woo checkout fields into a custom order across three lists (billing / shipping / order). Applies to the classic checkout via the `woocommerce_checkout_fields` filter. The per-product Checkout fields tab tables also follow this order, so admins see the same layout they'll get at checkout.
* PRO: **Drag-and-drop reordering** of rows in the Custom fields, Conditional logic and Field validation panels. Grab the ≡ handle on the left of any row to reorder.
* PRO: **Custom fields → Options** input now grays out and gets a "— only used for Dropdown —" placeholder whenever Type ≠ Dropdown. The value is retained in case you switch back to Dropdown, but the input is read-only and visually muted.

= 2.1.3 =
* PRO: **Fixed broken "+ Add" buttons in empty PRO panels.** The "+ Add custom field", "+ Add condition" and "+ Add validation rule" buttons silently did nothing on a product that didn't already have at least one row — the JS tried to clone the last existing row but there wasn't one. Each PRO panel now ships a hidden HTML template, and the add-row handlers fall back to that template when the tbody is empty.

= 2.1.2 =
* PRO Fix: License activation now uses the response from `/activate` directly — successful activation immediately writes the valid status and you no longer rely on a separate `/validate` roundtrip
* PRO Fix: Specific activation errors (wrong slug, expired, max activations, server unreachable) are stored in option `ocwcl_pro_last_error` and shown under the License Key field instead of a generic "Inactive"
* PRO: Stores `sites_used` and `sites_limit` from the server response on the cached status object

= 2.1.1 =
* Admin menu reorganized — "Checkout Fields" is now its own top-level item in the WP admin sidebar, positioned directly below WooCommerce. Tutorial, License & PRO, and Templates (PRO) live as submenus underneath it. Old WooCommerce submenu entries removed.
* Menu icon: WP `dashicons-feedback` (form-style icon).
* Pre-existing styling miss fixed: `admin.css` now loads on the Tutorial and License & PRO pages too (previously only on product edit screens), so the OCW house-style finally renders everywhere.

= 2.1.0 =
* PRO: **Configuration templates** — save the full checkout-fields configuration of a product as a named, reusable template (standard field statuses, custom fields, conditional logic, validation rules). Apply any saved template to another product in one click. New "Checkout Fields Templates" submenu under WooCommerce for rename/delete.
* New AJAX endpoints `ocwcl_template_save`, `ocwcl_template_apply`, `ocwcl_template_rename`, `ocwcl_template_delete` (all `manage_woocommerce` + nonce-protected).
* Stored as site option `ocwcl_pro_templates` (autoload off).
* License & PRO page now lists "Configuration templates" as a sixth PRO feature.

= 2.0.0 =
* Renamed to "OCW Checkout Logic for WooCommerce" (was "Woo Product Checkout Fields") to comply with the Woo trademark naming rule. New slug: `ocw-checkout-logic`.
* Single-codebase architecture (free + PRO from the same source). PRO ships as its own zip with `/includes/pro/`.
* All admin strings translated from Dutch to English (Dutch translations available via `/languages/`).
* New Tutorial submenu with progress detection and reset button. Auto-opens on first activation.
* New License & PRO submenu — paste your license key, see active features at a glance.
* OCW house-style admin design (teal / navy / pink, Apple-style cards).
* PRO: custom fields per product (text/email/phone/textarea/dropdown/checkbox).
* PRO: conditional logic — "show field X when field Y equals Z".
* PRO: per-category settings on `product_cat` terms.
* PRO: field validation patterns (Dutch postcode, KVK, EU VAT, IBAN, Dutch phone, custom regex).
* PRO: automatic updates via the OCW License Server.
* Plugin header bumped to `Requires at least: 6.0`, `Tested up to: 6.8`, `Requires PHP: 8.0`.
* `OCWCL_*` constants kept as back-compat aliases for `OCWCL_*`.

= 1.0.0 =
* Initial release
* Per-product checkout field control (Required / Optional / Hidden / Default)
* Billing, shipping and order-notes fields
* Quick bulk actions per product page
* HPOS and Blocks compatibility declared

== Upgrade Notice ==

= 2.4.0 =
Important fix for Cart & Checkout Blocks stores: hidden fields no longer write a space character into order addresses, and required fields are now enforced server-side. New uninstall.php cleans up all plugin data on deletion. No settings changes needed.

= 2.3.0 =
Plugin renamed to "OCW Checkout Logic for WooCommerce" (slug `ocw-checkout-logic`) for WordPress.org submission. All internal symbols renamed — option keys and post-meta keys reset, so per-product settings need to be reconfigured after upgrading.

= 2.2.3 =
WordPress.org plugin-directory readiness fixes (license headers, tested-up-to bump to 6.9, languages folder). No data changes.

= 2.2.2 =
Bugfix: Hidden fields now also disappear when the checkout form is rendered on the cart page (Elementor / Bricks / Divi setups). No data changes.

= 2.2.1 =
Bugfix: Hidden fields now actually disappear visually on the classic/Elementor checkout (label included, not just the input). No data changes.

= 2.2.0 =
New free feature: site-wide checkout field order via drag-and-drop. PRO: drag-and-drop on Custom fields / Conditional logic / Validation rules, plus clearer Options-column UX. No data changes.

= 2.1.3 =
PRO bugfix — the "+ Add custom field / condition / validation rule" buttons now also work on a product that has no existing rows yet. No data changes.

= 2.1.2 =
PRO fix: license activation now writes status from the activate response directly and surfaces the real reason (wrong slug, expired, etc.) when activation fails. Recommended.

= 2.1.1 =
Admin menu reorganization — "Checkout Fields" becomes a separate top-level item directly below WooCommerce. No data changes.

= 2.1.0 =
PRO adds configuration templates — save once, reuse across products. Drop-in upgrade, no migration needed.

= 2.0.0 =
Major rename and architecture change. Deactivate + delete the old "Woo Product Checkout Fields" first, then install `ocw-checkout-logic-v2.0.0.zip`. Existing per-product settings (`_ocwcl_field_settings`) are preserved.

= 1.0.0 =
First release.
