=== CWeb Product Finder for Gravity Forms ===
Contributors: alexandreminem
Tags: gravity forms, recommendation, product finder, scoring, quiz
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 8.0
Stable tag: 3.1.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Recommend products at the end of a Gravity Forms questionnaire. Rules-based scoring, no external API. Works with built-in CPT or WooCommerce.

== Description ==

CWeb Product Finder for Gravity Forms turns a Gravity Forms questionnaire into a product picker. At the end of the form, the plugin scores each of your products against the visitor's answers and displays the best match (plus a couple of alternatives) as styled cards.

The scoring engine is fully local PHP. No OpenAI, no Claude, no remote service. You define rules in a clear "When → Then" admin UI: when the visitor's answers match certain conditions, boost / penalize / exclude / require specific products.

= Highlights =

* **Two product sources**: built-in Recommended Products CPT, or your existing WooCommerce catalog.
* **Direct product targeting**: rules pick the products they affect by ID, no tag indirection. Auto-completed from your form's actual fields and choices.
* **AND / OR conditions**: combine multiple form answers in a single rule.
* **Four effects**: Boost (+N points), Penalize (−N points), Exclude (hard filter), Require (only required products are eligible).
* **No external API**: all scoring happens on your server. Predictable, free, and private.
* **Setup wizard** plus dedicated **Scoring Rules** and **Help** admin pages.
* **Hidden field auto-detection**: the plugin scans your form for hidden fields and picks the right one (or asks if there are several).
* **Example form included**: a small SaaS Plan Picker you can import and start tinkering with right away.
* **Theme-friendly CSS**: all classes prefixed `.cwebpf-*`, with CSS variables for colors and fonts.
* **AI fallback hook**: `cwebpf_ai_fallback_recommendation` filter lets you plug an AI service for ambiguous cases. No built-in API call.

= Typical use cases =

* Web hosting / VPS plan finder
* SaaS pricing wizard ("which plan is right for you?")
* Service quote estimator
* Insurance / financial product recommender
* B2B product configurator

= About the name =

This plugin is a third-party companion for **Gravity Forms** (a separately sold commercial plugin by Rocketgenius, Inc.). It is not affiliated with, sponsored by, or endorsed by Rocketgenius. The "for Gravity Forms" suffix simply signals compatibility. The "CWeb" prefix refers to **Collectif WEB**, the agency that maintains this plugin.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/cweb-product-finder-for-gravity-forms/`, or install through the **Plugins** menu in WordPress.
2. Activate the plugin.
3. Go to **Recommender → Setup** and follow the 5-step wizard.
4. Add your products under **Recommender → All Products** (or use existing WooCommerce products).
5. Paste the shortcode generated by the wizard into your Gravity Form confirmation.

== Frequently Asked Questions ==

= Does this plugin call any external API? =

No. All scoring happens locally in PHP. Your visitors' answers never leave your server.

= Does it require Gravity Forms? =

Yes. Gravity Forms is the questionnaire engine. The plugin is a companion that hooks into form submissions.

= Can I use my existing WooCommerce products? =

Yes. In the setup wizard, choose "WooCommerce products" as the source. Reference your existing products by ID in the scoring rules. The rule editor auto-completes from your catalog.

= How do I customize the look of the recommendation cards? =

All HTML uses classes prefixed `.cwebpf-*`. Colors and fonts are exposed as CSS custom properties (`--cwebpf-primary`, `--cwebpf-accent`, `--cwebpf-font-heading`, etc.). Override them in your theme stylesheet.

= Can I write my own scoring logic in PHP? =

Yes. The recommendation result and explanation pass through filters (`cwebpf_recommendation_explanation`, `cwebpf_form_id`, `cwebpf_field_id`, `cwebpf_fallback_contact_url`, `cwebpf_card_disclaimer`). Advanced users can also call `CWebPF_Recommendation_Engine::recommend()` directly.

= Where is the data stored? =

Recommendation rules: `wp_options` (`cwebpf_scoring_rules`, `cwebpf_form_config`, `cwebpf_product_source`). Products: the standard `wp_posts` / `wp_postmeta` tables (CPT `cwebpf_product` or WooCommerce products). No custom database tables are created.

== Screenshots ==

1. Setup wizard — welcome screen with automatic system check (Gravity Forms / WooCommerce detection).
2. Setup wizard — pick the Gravity Form to listen to; the hidden field that stores the JSON result is auto-detected.
3. Setup wizard — done. The shortcode is generated and ready to paste in the form confirmation message.
4. Add a product (built-in CPT) with price label, short description, features, page URL, payment URL and CTA label.
5. Scoring rules editor — combine "When" conditions (radio / dropdown / checkbox answers, AND/OR) with "Then" effects: Boost, Penalize, Exclude or Require a product.
6. Built-in Help &amp; About page — describes the scoring model, the shortcode, and the available developer filters.

== Changelog ==

= 3.1.3 =
* Plugin renamed to "CWeb Product Finder for Gravity Forms" with a distinctive `cweb-` prefix per WordPress.org naming guidelines.
* All internal identifiers (functions, classes, constants, options, post meta, CSS classes, CSS variables, filters, shortcode) renamed from `gr_*` / `GR_*` / `.gr-*` to `cwebpf_*` / `CWEBPF_*` / `CWebPF_*` / `.cwebpf-*` to satisfy the 4+ character prefix rule.
* All inline `<style>` and `<script>` blocks moved to standalone files in `assets/css/admin.css`, `assets/js/admin-rules.js`, and `assets/js/admin-onboarding.js`, registered via `wp_enqueue_style`, `wp_enqueue_script`, and localized with `wp_localize_script`. Each asset is conditionally loaded only on its own admin screen.
* Shortcode renamed: `[gravity_recommender]` → `[cwebpf_recommender]`.

= 3.1.2 =
* First WordPress.org submission attempt. Plugin renamed to "Product Finder for Gravity Forms".
* Plugin Checker: replaced `(int) wp_unslash(...)` with `absint(wp_unslash(...))` on `$_POST['gr_form_id']` and `$_GET['step']`. Static analyzers don't accept type casts as sanitization.
* Filter renamed: `gr_gravityforms_affiliate_url` → `gr_gravityforms_url`.
* Fixed self-referencing CSS custom properties in `:root`. Default colors and fonts now render even when the theme doesn't override them.
* LICENSE and license-string wording uniformized as "GPLv2 or later" across all files.

= 3.1.1 =
* Hotfix: critical fatal error on Setup step 3 ("Products"). The CPT product source was calling a method removed in 3.1.0.
* WordPress.org Plugin Checker compliance: removed `load_plugin_textdomain()` (auto-loaded since WP 4.6), added `languages/` folder, fixed `translators:` comment placement, switched to explicit per-field `wp_unslash() + sanitize_*()` chains across all admin pages.

= 3.1.0 =
* Scoring engine rewritten: rules target products directly by ID (no more tag indirection).
* New conditions builder with AND / OR logic and four effects per rule (Boost / Penalize / Exclude / Require).
* New dedicated "Scoring Rules" admin page.
* New "Help" admin page (how-it-works, shortcode, filters, credits).
* Hidden field auto-detection in the setup wizard.
* Wizard restructured: products are added before the form is wired.
* Graceful flow when Gravity Forms is missing (install/buy CTA, no broken state).
* Example form replaced with a generic SaaS Plan Picker.
* `gr_ai_fallback_recommendation` filter for plugging an optional AI fallback.

= 3.0.0 =
* First general-purpose release.
* Tag-based scoring engine.
* Custom Post Type for managing recommended products.
* WooCommerce product source support.
* 5-step setup wizard with example form import.
* CSS variables for theming.

== Upgrade Notice ==

= 3.1.3 =
Plugin renamed to "CWeb Product Finder for Gravity Forms" and all internal identifiers re-prefixed. This is NOT a drop-in upgrade from 3.1.x: stored options, post meta keys, shortcode name, and filter hooks were renamed. Fresh installs only.

= 3.1.2 =
Plugin renamed for WordPress.org submission. Drop-in upgrade from 3.1.x.

= 3.1.0 =
Major engine rewrite: rules now target products directly by ID instead of through tags. Existing tag-based configurations from 3.0.x will need to be re-authored in the new Scoring Rules page.
