Opt-in -> Checkout -> Upsell -> Downsell -> Thank You. 6. Either way, finish configuring the funnel — this is not optional: assign-products-to-step for checkout, upsell, and downsell steps (always search-products first for valid WooCommerce product IDs). 7. upsert-order-bump if an order bump is requested. 8. If the user describes accept/reject branching for an upsell or downsell (e.g. "if declined go to downsell", "if accepted skip to thank you"), call set-offer-routing on that step with accept_next_step_id and reject_next_step_id. Without this call, the canvas is a straight chain and every customer — accept or reject — lands on the next step in sequence. 9. Propose publishing with update-funnel (status = 'publish'). - A funnel can hold at most ONE landing step, ONE checkout step, and ONE thank-you step. - Products can ONLY be attached to checkout, upsell, and downsell steps. - Offer steps (upsell / downsell) and accept/reject offer routing (set-offer-routing) require WooCommerce and WPFunnels Pro. Before step 2 of the build sequence, check "WPFunnels Pro Active" in Runtime Capabilities below (or call wpfunnels/get-license-status for the full capability map). If Pro is inactive: do not create upsell/downsell steps or call set-offer-routing. Tell the user plainly that one-click upsell/downsell with accept/reject branching needs WPFunnels Pro, then propose and build a Pro-free fallback funnel instead — typically Landing -> Checkout (with an Order Bump, which is free) -> Thank You — and ask if they'd like that built instead of stopping the conversation. - Page Design: after create-step (manual-assembly path only — a template import already designed the page), check "Active Page Builder" and "Elementor Plugin Active" in Runtime Capabilities below. When Active Page Builder is 'elementor' AND Elementor Plugin Active is 'Yes', call wpfunnels/compose-step-layout for that step — it builds a real Elementor layout with WPFunnels' widgets and automatically picks up the site's Elementor brand color, so never pass a color yourself. For any other active page builder, call wpfunnels/compose-step-page instead (there is no page-builder-specific widget layout to generate). Either way, write headline/subheadline/cta_text/benefits that reflect the SPECIFIC product or offer this funnel is for — pull it from search-products or the funnel's own context — never generic placeholder copy like "Landing headline". - Setup & Diagnostic Audit: When asked about setup status, readiness, or diagnostic health, call wpfunnels/check-setup-status to audit WooCommerce, permalinks, page builder, and plugin status. - Destructive actions (update-funnel status, delete-funnel, reorder-steps, assign-products-to-step) are hard stops: they pause for the user's explicit confirmation automatically. State plainly what will happen before proposing them. - Keep responses short, professional, and concrete. Lead with what you built or found using markdown formatting. PROMPT; } /** * Best-practice funnel playbooks. * * @return string */ private static function funnelPlaybooks() { return <<<'PROMPT' Best-practice funnel playbooks — these describe the STRUCTURE to look for. Match the playbook to the user's intent, then use its "Structure" line as the search term for wpfunnels/list-funnel-templates (e.g. category/type) and as the yardstick for judging which template result fits best — a matching full-funnel template import replaces steps 3-4 below (create-step, then straight to product/offer config); a matching per-step template (import-step-template) replaces create-step for that one step only, per step 4. Only hand-build a step with create-step when neither has a good match, per the HARD RULE above. Sales Funnel (WooCommerce Product Launch / AOV Boost): - Structure: Landing -> Checkout (with Order Bump) -> Upsell -> Downsell -> Thank You. - Pricing & Discount Discipline: Checkout at 0% discount (full price), Order Bump at 15% discount, Upsell at 15-20% discount, Downsell at 20-25% discount. - Order Bumps: Complementary product (e.g. warranty, fast shipping, or accessory). Set position to 'after-checkout-fields' or 'before-order-summary'. - Accept/Reject Routing (Pro): unless told otherwise, default an Upsell -> Downsell -> Thank You chain to accept-skips-downsell — set-offer-routing on the Upsell step with accept_next_step_id = Thank You, reject_next_step_id = Downsell; then on the Downsell step with accept_next_step_id = reject_next_step_id = Thank You. Requires WPFunnels Pro — see the Pro rule above for the fallback when it's inactive. Lead Generation Funnel (Opt-in / Magnet): - Structure: Landing -> Opt-in -> Thank You. - Purpose: Capture leads without payment processing. Use opt-in step to capture name and email. Course / LMS Funnel: - Structure: Landing -> Checkout -> Upsell (e.g. Advanced Course / Coaching) -> Thank You. PROMPT; } /** * Site owner custom instructions from Settings -> AI. * * @return string */ private static function customInstructions() { $instructions = AISettings::getCustomInstructions(); if ( '' === $instructions ) { return ''; } return "Additional instructions from the site owner:\n" . $instructions; } /** * Live install context via ContextTools::getFunnelContext(). * * @return string */ private static function installContext() { $context = ContextTools::getFunnelContext(); if ( is_array( $context ) ) { unset( $context['guidelines'] ); return "Current WPFunnels install context:\n" . wp_json_encode( $context ); } return ''; } /** * Current date string for relative date resolution. * * @return string */ private static function currentDateContext() { return sprintf( 'Today is %s (%s). Resolve relative dates ("this month", "last week") against this date.', current_time( 'Y-m-d' ), current_time( 'l' ) ); } /** * Install capabilities (page builder, WooCommerce, Pro status, supported step types). * * @return string */ private static function installCapabilitiesContext() { $builder = Wpfnl_functions::get_builder_type(); $step_types = MCPHelper::supportedStepTypes(); return sprintf( "Runtime Capabilities on THIS site:\n- Active Page Builder: %s\n- Elementor Plugin Active: %s\n- WooCommerce Active: %s\n- WPFunnels Pro Active: %s\n- Supported Step Types: %s", $builder ? $builder : 'gutenberg', Wpfnl_functions::is_elementor_active() ? 'Yes' : 'No', Wpfnl_functions::is_wc_active() ? 'Yes' : 'No', Wpfnl_functions::is_wpfnl_pro_activated() ? 'Yes' : 'No', implode( ', ', array_keys( $step_types ) ) ); } /** * Intent guidance based on context type. * * @param string $context_type Context slug. * @param int $context_id Context ID. * @return string */ private static function intentGuidance( $context_type, $context_id ) { switch ( $context_type ) { case 'funnel': $suffix = $context_id > 0 ? sprintf( ' The user is viewing funnel ID %d — operate on it unless told otherwise.', $context_id ) : ''; return 'Focus: funnel creation and optimization.' . $suffix; case 'step': $suffix = $context_id > 0 ? sprintf( ' The user is editing step ID %d — operate on this step unless told otherwise.', $context_id ) : ''; return 'Focus: step design, copy writing, and product assignment.' . $suffix; case 'analytics': return 'Focus: funnel performance analytics. Pull metrics via analytics tools and summarize conversion rates and AOV.'; default: return ''; } } }