name = esc_html__( 'AI Score Badge', 'ai-discoverability-kit' ); } /** * Get module fields. * * @return array Field definitions. */ public function get_fields(): array { return array( 'badge_style' => array( 'label' => esc_html__( 'Badge Style', 'ai-discoverability-kit' ), 'type' => 'select', 'option_category' => 'layout', 'options' => array( 'badge' => esc_html__( 'Badge (Circle)', 'ai-discoverability-kit' ), 'bar' => esc_html__( 'Progress Bar', 'ai-discoverability-kit' ), 'minimal' => esc_html__( 'Minimal (Number)', 'ai-discoverability-kit' ), ), 'default' => 'badge', ), 'show_label' => array( 'label' => esc_html__( 'Show Label', 'ai-discoverability-kit' ), 'type' => 'yes_no_button', 'option_category' => 'configuration', 'options' => array( 'on' => esc_html__( 'Yes', 'ai-discoverability-kit' ), 'off' => esc_html__( 'No', 'ai-discoverability-kit' ), ), 'default' => 'on', ), 'primary_color' => array( 'label' => esc_html__( 'Primary Color', 'ai-discoverability-kit' ), 'type' => 'color-alpha', 'default' => '#00e58a', ), ); } /** * Render the module output. * * @param array $attrs Module attributes. * @param string|null $content Module content. * @param string $render_slug Module render slug. * * @return string HTML output. */ public function render( $attrs, $content, $render_slug ): string { $product_id = get_the_ID(); if ( ! function_exists( 'wc_get_product' ) ) { return ''; } $product = wc_get_product( $product_id ); if ( ! $product || ! $product->is_type( array( 'simple', 'variable', 'grouped', 'external' ) ) ) { return ''; } $readiness = new \AICommerce\Analytics\ReadinessScore( new \AICommerce\Schema\ProductSchema(), new \AICommerce\Schema\Validator() ); $result = $readiness->calculate_and_cache( $product ); $score = (int) ( $result['overall'] ?? 0 ); $style = $this->props['badge_style'] ?? 'badge'; $show_label = 'on' === ( $this->props['show_label'] ?? 'on' ); $color = $this->props['primary_color'] ?? '#00e58a'; if ( ! function_exists( 'aicommerce_render_score_badge' ) ) { return ''; } return aicommerce_render_score_badge( $score, $style, $show_label, $color ); } }