[ 'label' => __( 'Shop products', 'aisentic' ), 'description' => __( 'Find, compare and add to cart', 'aisentic' ), 'icon' => 'bag', 'matches_page' => static fn(): bool => ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) || ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ), ], 'label' => __( 'WooCommerce', 'aisentic' ), 'icon' => 'shopping-cart', 'slot' => 'wc-analytics', 'available' => fn(): bool => class_exists( 'WooCommerce' ), 'fields' => [ 'recommendedLimit' => [ 'type' => 'number', 'label' => __( 'Product Suggestions', 'aisentic' ), 'help' => __( 'Maximum number of products the assistant will recommend per search.', 'aisentic' ), 'min' => 1, 'max' => 12, 'default' => 3, ], 'searchCacheTtlSeconds' => [ 'type' => 'number', 'label' => __( 'Search Cache TTL (sec)', 'aisentic' ), 'help' => __( 'Seconds to cache product search results. Higher values reduce API calls but delay price and stock updates.', 'aisentic' ), 'min' => 30, 'default' => 300, ], 'outOfScopeMessage' => [ 'type' => 'textarea', 'label' => __( 'Out of Scope Message', 'aisentic' ), 'help' => __( 'Shown when a customer asks something outside the assistant\'s scope, such as order status or refunds.', 'aisentic' ), 'default' => 'I can help you find products and add them to your cart. For order issues, refunds, or account help, please contact support.', ], 'starterPrompts' => [ 'type' => 'prompts', 'label' => __( 'Starter Prompts', 'aisentic' ), 'help' => __( 'Quick-reply chips shown when the chat opens.', 'aisentic' ), 'max' => 8, 'maxChars' => 100, 'default' => [ 'What\'s on sale?', 'Show me your best sellers', 'Help me find a gift', 'What do you recommend?', ], ], ], ]; return $panels; } /** * Get services * * @return array */ public function get_services(): array { return []; } /** * Add WooCommerce tools to the public chat toolset * * @param array $tools Existing tools. * @param Settings $settings Settings instance. * @return array */ public function add_tools( array $tools, Settings $settings ): array { if ( ! $this->is_wc_active_and_enabled( $settings ) ) { return $tools; } $tools[] = new Wc_Product_Search_Tool( $settings ); $tools[] = new Wc_Cart_Action_Tool(); return $tools; } /** * Add WooCommerce sales prompt to the public chat instructions * * @param string $prompt Existing prompt. * @param Settings $settings Settings instance. * @return string */ public function add_instructions( string $prompt, Settings $settings ): string { if ( ! $this->is_wc_active_and_enabled( $settings ) ) { return $prompt; } $out_of_scope = (string) ( new Public_Agent_Settings( $settings ) ) ->integration( 'woocommerce', 'outOfScopeMessage' ); return $prompt . "\n\n" . WooCommerce_Prompt_Bank::get_sales_prompt( $out_of_scope ); } /** * Check if WooCommerce is active and the integration is enabled * * @param Settings $settings Settings instance. * @return bool */ private function is_wc_active_and_enabled( Settings $settings ): bool { // is_enabled() already checks the panel's `available` callback, which is // the class_exists( 'WooCommerce' ) guard. return ( new Public_Agent_Settings( $settings ) )->is_enabled( 'woocommerce' ); } }