We built DEV3 AI Product Options & Add-Ons as a WooCommerce plugin in PHP, with a React option-set builder and a storefront script that shares its pricing engine with the builder's live preview.
Key design decisions
- One grammar, two parsers, no eval. Price formulas are tokenised and parsed by a small recursive-descent parser written twice, in PHP and JavaScript, with ten whitelisted functions (min, max, round, ceil, floor, abs, sqrt, pow, if, clamp), a 500-character limit and division by zero defined as 0.
- The server is authoritative. The browser shows a live total, but on add to cart the server re-parses the posted values, re-runs conditions and validation, stores only the visible values, and recalculates prices in
woocommerce_before_calculate_totals for both the classic and block cart.
- Shared fixtures from an independent reference. 127 pricing cases are generated by a separate Python implementation of the rules. Both the PHPUnit and Jest suites must reproduce every expected unit price, one-off fee and total.
- A logic checker that needs no AI. It finds conditions that can never be true, loops (including loops through steps and sections), price conflicts and structural errors before a set is published.
- Global sets with precise assignment. Sets apply by category (including sub-categories), tag or product, with priorities, exclusions, per-product overrides and an "own fields only" mode.
- AI drafts only. With the Google Gemini API connected, DEV3 AI can draft a whole option set from a product description, review the logic, turn a plain-language rule into a formula, write labels and translations, and check uploaded images. Every result is a draft the merchant accepts or rejects.
Architecture
Option sets are stored as normalised field lists. The storefront renders them as accessible, translated markup (swatches, image pickers, steps, repeaters, uploads) and recalculates the total on every change with the shared engine. Uploads go to a protected folder with random names, type, size and minimum-resolution checks, and are deleted after a retention period if never ordered. Options flow into the cart, checkout, orders, emails and the admin, can be edited from the cart, and survive "order again". The API client, encrypted key storage and usage logs come from a shared core used across DEV3's plugins.